handling tool result from custom mcp server
The result from custom mcp server tools is in the following format: {message_id='02f1f150-df6e-47af-91d5-cf444e3a03ec' role='tool' content=[ToolResultBlock(type='tool_result', call_id='call_9e2ddebd538c4114968ffaf2b80c', output=[{'type': 'text', 'text': '{"location":"delhi","temperature":"22°C","description":"Sunny"}', 'annotations': None, 'meta': None}], is_error=False, status='completed')] delta=False tools_calls=None reasoning=None timestamp=1760500251.480908 metadata={'function_name': 'get_weather', 'function_argument': {'location': 'delhi'}, 'tool_call_id': 'call_9e2ddebd538c4114968ffaf2b80c'} usages=None raw=None}
(https://github.com/10xHub/Agentflow/blob/main/agentflow/utils/converter.py) But in the code, when converting messages from state, it is just using message.text() method to get the data (which is giving empty string ).
But the actual data is in message.content[0].output[0]['text'].
so we need to either add a line like the following, or change the code in any other way to make it work for all the tool result block formats.
if message.text() == "" and content and content[0].output: return {"role": message.role, "content": content[0].output[0]['text'], "tool_call_id": call_id}