JSON Response Parser¶
Configurable parser for custom HTTP and WebSocket response structures.
mapping
¶
Configurable parser for custom JSON response structures.
JsonResponseParser
¶
JsonResponseParser(*, tool_calls_key: str = 'tool_calls', name_key: str = 'name', arguments_key: str = 'arguments', single: bool = False)
Configurable parser for endpoints that return tool calls in a custom JSON structure.
Instead of writing a full parser class, pass field name config to match whatever your HTTP or WebSocket endpoint returns.
| PARAMETER | DESCRIPTION |
|---|---|
tool_calls_key
|
Dot-separated path to the tool calls in the response.
Supports nested paths (e.g.
TYPE:
|
name_key
|
Key for the function name within each tool call dict.
Default:
TYPE:
|
arguments_key
|
Key for the arguments dict within each tool call.
Default:
TYPE:
|
single
|
Set to
TYPE:
|
Usage::
# Endpoint returns: {"toolCall": {"name": "fn", "arguments": {...}}}
parser = JsonResponseParser(tool_calls_key="toolCall", single=True)
# Endpoint returns: {"result": {"calls": [{"fn": "...", "params": {...}}]}}
parser = JsonResponseParser(
tool_calls_key="result.calls",
name_key="fn",
arguments_key="params",
)
# Use with HttpAgent or WebSocketAgent
agent = HttpAgent(url="http://localhost:8000/agent", parser=parser)
agent = WebSocketAgent(url="ws://localhost:8000/ws", parser=parser)
Source code in src/russo/parsers/mapping.py
parse
¶
parse(raw_response: Any) -> AgentResponse
Parse a JSON response into a normalized AgentResponse.