Add custom agent example using HUD Gateway for inference#223
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
examples/05_custom_agent.py
Outdated
| async def get_system_messages(self) -> list[types.ContentBlock]: | ||
| """Return system prompt as content blocks.""" | ||
| system_text = self.system_prompt or "You are a helpful assistant." | ||
| return [types.TextContent(type="text", text=system_text)] |
There was a problem hiding this comment.
Build system messages in OpenAI chat format
In examples/05_custom_agent.py lines 63-66, get_system_messages returns mcp.types.TextContent objects. _run_context passes these messages directly into AsyncOpenAI.chat.completions.create, which expects dictionaries with role/content. Supplying ContentBlock instances will raise OpenAI client validation/type errors before any inference runs, so the example crashes immediately. Construct system messages as OpenAI-style dicts (as in other OpenAI agents) instead of MCP content blocks.
Useful? React with 👍 / 👎.
Parth220
left a comment
There was a problem hiding this comment.
We should update the docs to reference this file for hud gateway
Note
Adds a new custom MCPAgent example using HUD Gateway with tracing and updates gateway docs to link and describe it.
examples/05_custom_agent.pyMyAgent(MCPAgent) using HUD Gateway via OpenAI-compatible clientget_responsewith@instrumentfor tracing and usage loggingdocs/gateway/index.mdx): Add “Building Custom Agents with Tracing” section linking to the new example, highlighting@instrument, MCPAgent usage, automatic token/latency tracking, and HUD Dashboard for traces.Written by Cursor Bugbot for commit 5536010. This will update automatically on new commits. Configure here.