-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy path__init__.py
More file actions
79 lines (61 loc) · 2.29 KB
/
Copy path__init__.py
File metadata and controls
79 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from __future__ import annotations
from typing import Any
from .base import CategorizedTools, MCPAgent
from .openai import OpenAIAgent
from .openai_chat import OpenAIChatAgent
from .operator import OperatorAgent
__all__ = [
"CategorizedTools",
"MCPAgent",
"OpenAIAgent",
"OpenAIChatAgent",
"OperatorAgent",
"create_agent",
]
def create_agent(model: str, **kwargs: Any) -> MCPAgent:
"""Create an agent for a gateway model.
This routes ALL requests through the HUD gateway. For direct API access
(using your own API keys), use the agent classes directly.
Args:
model: Model name (e.g., "gpt-4o", "claude-sonnet-4-5").
**kwargs: Additional params passed to agent.create().
Returns:
Configured MCPAgent instance with gateway routing.
Example:
```python
# Gateway routing (recommended)
agent = create_agent("gpt-4o")
agent = create_agent("claude-sonnet-4-5", temperature=0.7)
# Direct API access (use agent classes)
from hud.agents.claude import ClaudeAgent
agent = ClaudeAgent.create(model="claude-sonnet-4-5")
```
"""
from hud.agents.gateway import build_gateway_client
from hud.agents.resolver import resolve_cls
# Resolve class and gateway info
agent_cls, gateway_info = resolve_cls(model)
# Get model name from gateway info or use input
model_id = model
if gateway_info:
model_id = gateway_info.get("model_name") or model
# Determine provider: from gateway info, or infer from agent class
if gateway_info:
provider = gateway_info["provider"]["name"]
else:
provider = "openai"
if agent_cls.__name__ == "ClaudeAgent":
provider = "anthropic"
elif agent_cls.__name__ in ("GeminiAgent", "GeminiCUAAgent"):
provider = "gemini"
client = build_gateway_client(provider)
# Set up kwargs
kwargs.setdefault("model", model_id)
# Use correct client key based on agent type
if agent_cls == OpenAIChatAgent:
kwargs.setdefault("openai_client", client)
else:
# Claude and other agents use model_client and validate_api_key
kwargs.setdefault("model_client", client)
kwargs.setdefault("validate_api_key", False)
return agent_cls.create(**kwargs)