Skip to content

TypeScript fromChatMessages does not properly interpret function_calls #181

@ryankashi

Description

@ryankashi

const chatMessages: Message[] = [
	{ role: 'user', content: 'What is the weather?' },
	{
		role: 'assistant',
		content: null,
		toolCalls: [
			{
				id: 'call_123',
				type: 'function',
				function: { name: 'get_weather', arguments: '{"location":"Paris"}' }
			}
		]
	},
	{
		role: 'tool',
		toolCallId: 'call_123',
		content: '{"temperature": 20}'
	}
];
const input = fromChatMessages(chatMessages);
console.log('got input:');
console.log(input);

this prints:

got input:
[
  { role: 'user', content: 'What is the weather?' },
  { role: 'assistant', content: '' },
  {
    type: 'function_call_output',
    callId: 'call_123',
    output: '{"temperature": 20}'
  }
]

Instead, it should print:


[
  { role: 'user', content: 'What is the weather?' },
  { type: 'function_call', name: 'get_weather', arguments: '{"location":"Paris"}' , callId: 'call_123' },
  {
    type: 'function_call_output',
    callId: 'call_123',
    output: '{"temperature": 20}'
  }
]

Notice how the tool_call message is improperly converted to a blank assistant message when instead it should be converted to a function_call. This breaks Agentic loops that want to call LLMs using openRouter.callModel, since the input tool request is not properly created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions