Parsers¶
Built-in response parsers for normalizing provider-specific tool call formats.
parsers
¶
Built-in response parsers for normalizing provider-specific tool call formats.
GeminiResponseParser
¶
Parses Gemini GenerateContentResponse into AgentResponse.
Handles the Gemini response format where tool calls appear as function_call parts in response.candidates[].content.parts[].
Works with both the raw dict format and the google-genai SDK objects.
Usage
parser = GeminiResponseParser() response = parser.parse(gemini_raw_response)
parse
¶
parse(raw_response: Any) -> AgentResponse
Parse a Gemini response into a normalized AgentResponse.
Source code in src/russo/parsers/gemini.py
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.
Source code in src/russo/parsers/mapping.py
OpenAIResponseParser
¶
Parses OpenAI ChatCompletion responses into AgentResponse.
Handles the OpenAI format where tool calls appear at: response.choices[].message.tool_calls[]
Each tool call has: {id, type, function: {name, arguments}}.
Works with both the raw dict format and the openai SDK objects.
Usage
parser = OpenAIResponseParser() response = parser.parse(openai_raw_response)
parse
¶
parse(raw_response: Any) -> AgentResponse
Parse an OpenAI response into a normalized AgentResponse.