Skip to content

Commit e73f164

Browse files
committed
update GenericOpenAIChatAgent and MCPAgent for improved parameter handling and documentation
1 parent ffbe773 commit e73f164

File tree

8 files changed

+278
-331
lines changed

8 files changed

+278
-331
lines changed

docs/reference/agents.mdx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,31 @@ OpenAI's Operator agent implementation.
139139
from hud.agents import GenericOpenAIChatAgent
140140
```
141141

142-
Generic OpenAI chat completion agent for any OpenAI-compatible API.
142+
OpenAI-compatible chat.completions agent that works with any API implementing the OpenAI schema (e.g., OpenAI, vLLM, Ollama, Together, etc.).
143143

144144
**Constructor Parameters:**
145145
| Parameter | Type | Description | Default |
146146
|-----------|------|-------------|---------|
147-
| `model_client` | `AsyncOpenAI` | OpenAI-compatible client | Required |
148-
| `model` | `str` | Model name | Required |
149-
| `max_tokens` | `int` | Maximum response tokens | `4096` |
147+
| `openai_client` | `AsyncOpenAI` | OpenAI-compatible client instance | Required |
148+
| `model_name` | `str` | Chat model name | `"gpt-4o-mini"` |
149+
| `parallel_tool_calls` | `bool` | Allow multiple tool calls per turn | `False` |
150+
| `completion_kwargs` | `dict[str, Any]` | Extra args for `chat.completions.create` (e.g., temperature) | `{}` |
150151

151-
**Example:**
152+
**Example (local or custom endpoint):**
152153
```python
153-
# Use with local LLM
154154
from openai import AsyncOpenAI
155155

156-
client = AsyncOpenAI(
157-
base_url="http://localhost:11434/v1", # Ollama
158-
api_key="not-needed"
156+
openai_client = AsyncOpenAI(
157+
base_url="http://localhost:11434/v1", # e.g., Ollama
158+
api_key="not-needed",
159159
)
160160

161-
agent = GenericOpenAIChatAgent(
162-
model_client=client,
163-
model="llama3.1"
164-
)
161+
agent = GenericOpenAIChatAgent(
162+
openai_client=openai_client,
163+
model_name="llama3.1",
164+
parallel_tool_calls=False,
165+
completion_kwargs={"temperature": 0.2}, # forwarded to OpenAI
166+
)
165167
```
166168

167169
### LangChainAgent
@@ -385,4 +387,3 @@ class MyCustomAgent(MCPAgent):
385387
- [Create Agents](/evaluate-agents/create-agents) - Tutorial on building agents
386388
- [Tasks](/reference/tasks) - Task configuration reference
387389
- [Architecture](/core-concepts/architecture) - How agents fit in HUD
388-

docs/reference/api/agents.mdx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ agent = OperatorAgent(
190190

191191
## GenericOpenAIChatAgent
192192

193-
Generic OpenAI-compatible chat agent for custom models.
193+
OpenAI-compatible chat.completions agent for custom models and endpoints.
194194

195195
```python
196196
from hud.agents import GenericOpenAIChatAgent
@@ -200,27 +200,48 @@ from hud.agents import GenericOpenAIChatAgent
200200

201201
```python
202202
GenericOpenAIChatAgent(
203-
model: str = "gpt-4o",
204-
base_url: str | None = None,
203+
*,
204+
openai_client: AsyncOpenAI,
205+
model_name: str = "gpt-4o-mini",
206+
parallel_tool_calls: bool = False,
207+
completion_kwargs: dict[str, Any] | None = None,
205208
**kwargs
206209
)
207210
```
208211

209-
<ParamField body="model" type="str" default="gpt-4o">
210-
Model name to use
212+
<!-- MCP client is optional via kwargs; typically auto-created from Task.mcp_config -->
213+
214+
<ParamField body="openai_client" type="AsyncOpenAI" required>
215+
OpenAI-compatible client (can target OpenAI, vLLM, Ollama, etc.)
211216
</ParamField>
212217

213-
<ParamField body="base_url" type="str" optional>
214-
Custom API endpoint for OpenAI-compatible servers
218+
<ParamField body="model_name" type="str" default="gpt-4o-mini">
219+
Name of the chat model to use
220+
</ParamField>
221+
222+
<ParamField body="parallel_tool_calls" type="bool" default="false">
223+
Whether to execute multiple tool calls in a single step
224+
</ParamField>
225+
226+
<ParamField body="completion_kwargs" type="dict[str, Any]" optional>
227+
Extra keyword arguments forwarded to `openai.chat.completions.create` (e.g., `temperature`, `top_p`).
228+
Core fields (`model`, `messages`, `tools`, `parallel_tool_calls`) are protected and cannot be overridden. Use this field to set `logprobs` if needed.
215229
</ParamField>
216230

217231
### Example
218232

219233
```python
220-
# Custom OpenAI-compatible model
234+
from openai import AsyncOpenAI
235+
236+
openai_client = AsyncOpenAI(
237+
base_url="http://localhost:8000/v1", # Custom server
238+
api_key="local-key",
239+
)
240+
221241
agent = GenericOpenAIChatAgent(
222-
model="custom-model",
223-
base_url="http://localhost:8000/v1"
242+
openai_client=openai_client,
243+
model_name="custom-model",
244+
completion_kwargs={"temperature": 0.1, "seed": 7},
224245
)
225246
```
226247

@@ -344,5 +365,3 @@ except Exception as e:
344365
<Card title="Environments API" icon="cube" href="/reference/api/environments">
345366
Environment and server API reference
346367
</Card>
347-
348-

examples/README.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ python examples/01_hello_2048.py
2020

2121
> | Requires Docker and `ANTHROPIC_API_KEY` environment variable.
2222
23+
### 03_browser_agent_loop.py
24+
Quick start for the browser environment (Claude). Supports multiple demo apps.
25+
26+
```bash
27+
# 2048 (default)
28+
python examples/03_browser_agent_loop.py
29+
30+
# Todo app
31+
python examples/03_browser_agent_loop.py --app todo
32+
```
33+
34+
> | Requires Docker (exposes port 8080) and `ANTHROPIC_API_KEY`.
35+
2336
## Core Patterns
2437

2538
### 02_agent_lifecycle.py
@@ -50,35 +63,12 @@ Using the legacy `mcp_use` client for multi-server setups.
5063
### integration_otel.py
5164
Custom OpenTelemetry backend integration (e.g., Jaeger).
5265

53-
## Prerequisites
54-
55-
| Requirement | Used For |
56-
|-------------|----------|
57-
| Docker | Running environment containers |
58-
| `HUD_API_KEY` | Cloud deployments and telemetry |
59-
| `ANTHROPIC_API_KEY` | Claude agent examples |
66+
### openai_compatible_agent.py
67+
OpenAI-compatible chat.completions agent with both text and browser 2048 environments.
6068

61-
## Common Pattern
62-
63-
All examples follow this structure:
64-
65-
```python
66-
import asyncio, hud
67-
from hud.datasets import Task
68-
from hud.agents import ClaudeAgent
69-
70-
async def main():
71-
with hud.trace("example-name"):
72-
task = Task(
73-
prompt="Your task here",
74-
mcp_config={...}
75-
)
76-
77-
agent = ClaudeAgent()
78-
result = await agent.run(task)
79-
print(f"Reward: {result.reward}")
80-
81-
asyncio.run(main())
69+
```bash
70+
export OPENAI_API_KEY=your-key # or dummy value for local servers
71+
# export OPENAI_BASE_URL=http://localhost:8000/v1 # e.g., vllm
72+
python examples/openai_compatible_agent.py --mode text # text environment
73+
python examples/openai_compatible_agent.py --mode browser # browser environment
8274
```
83-
84-
> | The agent automatically creates an MCP client from `task.mcp_config` if none is provided.

examples/openai_compatible_2048.py

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)