|
26 | 26 | BaseMessage,
|
27 | 27 | HumanMessage,
|
28 | 28 | SystemMessage,
|
| 29 | + ToolMessage, |
29 | 30 | )
|
30 | 31 | from langchain_core.prompt_values import ChatPromptValue, StringPromptValue
|
31 | 32 | from langchain_core.runnables import Runnable, RunnableConfig, RunnableSerializable
|
@@ -234,11 +235,23 @@ def _create_passthrough_messages(self, _input) -> List[Dict[str, Any]]:
|
234 | 235 | def _message_to_dict(self, msg: BaseMessage) -> Dict[str, Any]:
|
235 | 236 | """Convert a BaseMessage to dictionary format."""
|
236 | 237 | if isinstance(msg, AIMessage):
|
237 |
| - return {"role": "assistant", "content": msg.content} |
| 238 | + result = {"role": "assistant", "content": msg.content} |
| 239 | + if hasattr(msg, "tool_calls") and msg.tool_calls: |
| 240 | + result["tool_calls"] = msg.tool_calls |
| 241 | + return result |
238 | 242 | elif isinstance(msg, HumanMessage):
|
239 | 243 | return {"role": "user", "content": msg.content}
|
240 | 244 | elif isinstance(msg, SystemMessage):
|
241 | 245 | return {"role": "system", "content": msg.content}
|
| 246 | + elif isinstance(msg, ToolMessage): |
| 247 | + result = { |
| 248 | + "role": "tool", |
| 249 | + "content": msg.content, |
| 250 | + "tool_call_id": msg.tool_call_id, |
| 251 | + } |
| 252 | + if hasattr(msg, "name") and msg.name: |
| 253 | + result["name"] = msg.name |
| 254 | + return result |
242 | 255 | else: # Handle other message types
|
243 | 256 | role = getattr(msg, "type", "user")
|
244 | 257 | return {"role": role, "content": msg.content}
|
|
0 commit comments