Spaces:
Sleeping
Sleeping
New heterogeneous managed agent
Browse files
agent_server/chat_completions.py
CHANGED
|
@@ -22,7 +22,9 @@ from agents.json_tool_calling_agents import (
|
|
| 22 |
)
|
| 23 |
|
| 24 |
from agents.agent_with_custom_beam_design_tools import generate_beam_agent
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Model name from env
|
| 28 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen3-1.7B")
|
|
@@ -85,6 +87,8 @@ def agent_for_model(model_name: str):
|
|
| 85 |
return generate_generator_with_managed_critic()
|
| 86 |
if model_name == "custom-agent-with-beam-design-tools":
|
| 87 |
return generate_beam_agent()
|
|
|
|
|
|
|
| 88 |
raise ValueError(f"Unknown model id: {model_name}")
|
| 89 |
|
| 90 |
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
from agents.agent_with_custom_beam_design_tools import generate_beam_agent
|
| 25 |
+
from agents.manager_with_heterogeneous_agents import (
|
| 26 |
+
generate_manager_with_heterogeneous_agents,
|
| 27 |
+
)
|
| 28 |
|
| 29 |
# Model name from env
|
| 30 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen3-1.7B")
|
|
|
|
| 87 |
return generate_generator_with_managed_critic()
|
| 88 |
if model_name == "custom-agent-with-beam-design-tools":
|
| 89 |
return generate_beam_agent()
|
| 90 |
+
if model_name == "manager-with-heterogeneous-agents":
|
| 91 |
+
return generate_manager_with_heterogeneous_agents()
|
| 92 |
raise ValueError(f"Unknown model id: {model_name}")
|
| 93 |
|
| 94 |
|
agent_server/models.py
CHANGED
|
@@ -13,46 +13,52 @@ def models_payload() -> dict:
|
|
| 13 |
"object": "list",
|
| 14 |
"data": [
|
| 15 |
{
|
| 16 |
-
"id":
|
| 17 |
"object": "model",
|
| 18 |
"created": now,
|
| 19 |
-
"owned_by": "
|
| 20 |
},
|
| 21 |
{
|
| 22 |
-
"id": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"object": "model",
|
| 24 |
"created": now,
|
| 25 |
"owned_by": "you",
|
| 26 |
},
|
| 27 |
{
|
| 28 |
-
"id": "
|
| 29 |
"object": "model",
|
| 30 |
"created": now,
|
| 31 |
"owned_by": "you",
|
| 32 |
},
|
| 33 |
{
|
| 34 |
-
"id": "
|
| 35 |
"object": "model",
|
| 36 |
"created": now,
|
| 37 |
"owned_by": "you",
|
| 38 |
},
|
| 39 |
{
|
| 40 |
-
"id": "
|
| 41 |
"object": "model",
|
| 42 |
"created": now,
|
| 43 |
"owned_by": "you",
|
| 44 |
},
|
| 45 |
{
|
| 46 |
-
"id":
|
| 47 |
"object": "model",
|
| 48 |
"created": now,
|
| 49 |
-
"owned_by": "
|
| 50 |
},
|
| 51 |
{
|
| 52 |
-
"id":
|
| 53 |
"object": "model",
|
| 54 |
"created": now,
|
| 55 |
-
"owned_by": "
|
| 56 |
},
|
| 57 |
],
|
| 58 |
}
|
|
|
|
| 13 |
"object": "list",
|
| 14 |
"data": [
|
| 15 |
{
|
| 16 |
+
"id": MODEL_NAME,
|
| 17 |
"object": "model",
|
| 18 |
"created": now,
|
| 19 |
+
"owned_by": "upstream",
|
| 20 |
},
|
| 21 |
{
|
| 22 |
+
"id": f"{MODEL_NAME}-nothink",
|
| 23 |
+
"object": "model",
|
| 24 |
+
"created": now,
|
| 25 |
+
"owned_by": "upstream",
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"id": "code-writing-agent-without-tools",
|
| 29 |
"object": "model",
|
| 30 |
"created": now,
|
| 31 |
"owned_by": "you",
|
| 32 |
},
|
| 33 |
{
|
| 34 |
+
"id": "code-writing-agent-with-search",
|
| 35 |
"object": "model",
|
| 36 |
"created": now,
|
| 37 |
"owned_by": "you",
|
| 38 |
},
|
| 39 |
{
|
| 40 |
+
"id": "tool-calling-agent-with-search-and-code",
|
| 41 |
"object": "model",
|
| 42 |
"created": now,
|
| 43 |
"owned_by": "you",
|
| 44 |
},
|
| 45 |
{
|
| 46 |
+
"id": "custom-agent-with-beam-design-tools",
|
| 47 |
"object": "model",
|
| 48 |
"created": now,
|
| 49 |
"owned_by": "you",
|
| 50 |
},
|
| 51 |
{
|
| 52 |
+
"id": "generator-with-managed-critic",
|
| 53 |
"object": "model",
|
| 54 |
"created": now,
|
| 55 |
+
"owned_by": "you",
|
| 56 |
},
|
| 57 |
{
|
| 58 |
+
"id": "manager-with-heterogeneous-agents",
|
| 59 |
"object": "model",
|
| 60 |
"created": now,
|
| 61 |
+
"owned_by": "you",
|
| 62 |
},
|
| 63 |
],
|
| 64 |
}
|
agents/manager_with_heterogeneous_agents.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import smolagents.models
|
| 6 |
+
from smolagents import ToolCallingAgent
|
| 7 |
+
import agents.code_writing_agents
|
| 8 |
+
import agents.agent_with_custom_beam_design_tools
|
| 9 |
+
|
| 10 |
+
INSTRUCTIONS = (
|
| 11 |
+
"You are a manager agent with access to two specialized subagents."
|
| 12 |
+
"Your primary task is to delegate tasks to the appropriate subagent based on their expertise."
|
| 13 |
+
)
|
| 14 |
+
AGENTS = [
|
| 15 |
+
agents.code_writing_agents.generate_code_writing_agent_with_search(),
|
| 16 |
+
agents.agent_with_custom_beam_design_tools.generate_beam_agent(),
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# ---------------- Factory ----------------
|
| 21 |
+
def generate_manager_with_heterogeneous_agents() -> ToolCallingAgent:
|
| 22 |
+
"""
|
| 23 |
+
Returns a CodeAgent (generator) that manages a critic sub-agent.
|
| 24 |
+
The critic is exposed to the generator as a managed agent (callable like a tool).
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
model = smolagents.models.OpenAIServerModel(
|
| 28 |
+
model_id=os.getenv("AGENT_MODEL", ""),
|
| 29 |
+
api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
|
| 30 |
+
api_key=os.getenv("OPENAI_API_KEY"),
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
generator = ToolCallingAgent(
|
| 34 |
+
tools=[], # keep toolbox minimal
|
| 35 |
+
model=model,
|
| 36 |
+
name="manager_with_heterogeneous_agents",
|
| 37 |
+
managed_agents=AGENTS,
|
| 38 |
+
instructions=INSTRUCTIONS,
|
| 39 |
+
add_base_tools=False,
|
| 40 |
+
max_steps=2,
|
| 41 |
+
)
|
| 42 |
+
return generator
|