diff --git a/agent/agents/product.py b/agent/agents/product.py index ae05210..f2ba0f7 100644 --- a/agent/agents/product.py +++ b/agent/agents/product.py @@ -185,6 +185,8 @@ async def product_agent(state: AgentState) -> AgentState: content = content.split("```")[1] if content.startswith("json"): content = content[4:] + # Remove leading/trailing whitespace after removing code block markers + content = content.strip() # Handle non-JSON format: "tool_name\n{args}" if '\n' in content and not content.startswith('{'): @@ -214,9 +216,17 @@ async def product_agent(state: AgentState) -> AgentState: if action == "call_tool": arguments = result.get("arguments", {}) + tool_name = result.get("tool_name", "") + + logger.info( + "Product agent calling tool", + tool_name=tool_name, + arguments=arguments, + conversation_id=state["conversation_id"] + ) # Inject context for product search (Mall API) - if result["tool_name"] == "search_products": + if tool_name == "search_products": arguments["user_token"] = state.get("user_token") arguments["user_id"] = state["user_id"] arguments["account_id"] = state["account_id"] @@ -230,24 +240,24 @@ async def product_agent(state: AgentState) -> AgentState: ) # Inject context for recommendation - if result["tool_name"] == "recommend_products": + if tool_name == "recommend_products": arguments["user_id"] = state["user_id"] arguments["account_id"] = state["account_id"] # Inject context for quote - if result["tool_name"] == "get_quote": + if tool_name == "get_quote": arguments["account_id"] = state["account_id"] - + # Use entity if available if "product_id" not in arguments and state["entities"].get("product_id"): arguments["product_id"] = state["entities"]["product_id"] - + if "quantity" not in arguments and state["entities"].get("quantity"): arguments["quantity"] = state["entities"]["quantity"] - + state = add_tool_call( state, - tool_name=result["tool_name"], + tool_name=tool_name, arguments=arguments, server="product" )