Spaces:
Sleeping
Sleeping
Adding more agents
Browse files
agents/{code_writing_agent.py → code_writing_agents.py}
RENAMED
|
@@ -3,14 +3,16 @@ import smolagents
|
|
| 3 |
import smolagents.models
|
| 4 |
|
| 5 |
|
| 6 |
-
def generate_code_writing_agent_with_tools(
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
Create a code-writing agent without any extra tools.
|
| 9 |
"""
|
| 10 |
if tools is None:
|
| 11 |
tools = []
|
| 12 |
return smolagents.CodeAgent(
|
| 13 |
-
name=
|
| 14 |
model=smolagents.models.OpenAIServerModel(
|
| 15 |
model_id=os.getenv("AGENT_MODEL", ""),
|
| 16 |
api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
|
|
@@ -37,4 +39,6 @@ def generate_code_writing_agent_with_search():
|
|
| 37 |
Create a code-writing agent without any extra tools.
|
| 38 |
"""
|
| 39 |
tools = [smolagents.WebSearchTool(max_results=5)]
|
| 40 |
-
return generate_code_writing_agent_with_tools(
|
|
|
|
|
|
|
|
|
| 3 |
import smolagents.models
|
| 4 |
|
| 5 |
|
| 6 |
+
def generate_code_writing_agent_with_tools(
|
| 7 |
+
tools=None, name: str = "code_writing_agent_without_tools"
|
| 8 |
+
):
|
| 9 |
"""
|
| 10 |
Create a code-writing agent without any extra tools.
|
| 11 |
"""
|
| 12 |
if tools is None:
|
| 13 |
tools = []
|
| 14 |
return smolagents.CodeAgent(
|
| 15 |
+
name=name,
|
| 16 |
model=smolagents.models.OpenAIServerModel(
|
| 17 |
model_id=os.getenv("AGENT_MODEL", ""),
|
| 18 |
api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
|
|
|
|
| 39 |
Create a code-writing agent without any extra tools.
|
| 40 |
"""
|
| 41 |
tools = [smolagents.WebSearchTool(max_results=5)]
|
| 42 |
+
return generate_code_writing_agent_with_tools(
|
| 43 |
+
tools, name="code_writing_agent_with_search"
|
| 44 |
+
)
|
agents/json_tool_calling_agents.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import smolagents
|
| 3 |
+
import smolagents.models
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def generate_tool_calling_agent_with_tools(
|
| 7 |
+
tools=None, name: str = "tool_calling_agent_without_tools"
|
| 8 |
+
):
|
| 9 |
+
"""
|
| 10 |
+
Create a code-writing agent without any extra tools.
|
| 11 |
+
"""
|
| 12 |
+
if tools is None:
|
| 13 |
+
tools = []
|
| 14 |
+
return smolagents.ToolCallingAgent(
|
| 15 |
+
name=name,
|
| 16 |
+
model=smolagents.models.OpenAIServerModel(
|
| 17 |
+
model_id=os.getenv("AGENT_MODEL", ""),
|
| 18 |
+
api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
|
| 19 |
+
api_key=os.getenv("OPENAI_API_KEY"),
|
| 20 |
+
),
|
| 21 |
+
tools=tools,
|
| 22 |
+
add_base_tools=False,
|
| 23 |
+
max_steps=4,
|
| 24 |
+
verbosity_level=int(
|
| 25 |
+
os.getenv("AGENT_VERBOSITY", "1")
|
| 26 |
+
), # quieter by default; override via env
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def generate_self_critiquing_agent():
|
| 31 |
+
"""
|
| 32 |
+
Create a code-writing agent without any extra tools.
|
| 33 |
+
"""
|
| 34 |
+
return generate_tool_calling_agent_with_tools(name="self_critiquing_agent")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def generate_code_writing_agent_with_search_and_code():
|
| 38 |
+
"""
|
| 39 |
+
Create a code-writing agent without any extra tools.
|
| 40 |
+
"""
|
| 41 |
+
tools = [
|
| 42 |
+
smolagents.WebSearchTool(max_results=5),
|
| 43 |
+
smolagents.PythonInterpreterTool(),
|
| 44 |
+
]
|
| 45 |
+
return generate_tool_calling_agent_with_tools(
|
| 46 |
+
tools, name="tool_calling_agent_with_search_and_code"
|
| 47 |
+
)
|
proxy.py
CHANGED
|
@@ -19,11 +19,16 @@ import contextlib
|
|
| 19 |
# Upstream pass-through
|
| 20 |
import httpx
|
| 21 |
|
| 22 |
-
from agents.
|
| 23 |
generate_code_writing_agent_without_tools,
|
| 24 |
generate_code_writing_agent_with_search,
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Logging setup
|
| 28 |
logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO").upper())
|
| 29 |
log = logging.getLogger(__name__)
|
|
@@ -620,12 +625,23 @@ async def list_models():
|
|
| 620 |
return {
|
| 621 |
"object": "list",
|
| 622 |
"data": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 623 |
{
|
| 624 |
"id": "code-writing-agent-without-tools",
|
| 625 |
"object": "model",
|
| 626 |
"created": now,
|
| 627 |
"owned_by": "you",
|
| 628 |
-
"logoUrl": "https://cmccomb.com/assets/images/headshot_optimized_square.jpg",
|
| 629 |
},
|
| 630 |
{
|
| 631 |
"id": "code-writing-agent-with-search",
|
|
@@ -706,6 +722,12 @@ async def chat_completions(req: fastapi.Request):
|
|
| 706 |
agent_for_request = generate_code_writing_agent_without_tools()
|
| 707 |
elif model_name == "code-writing-agent-with-search":
|
| 708 |
agent_for_request = generate_code_writing_agent_with_search()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 709 |
else:
|
| 710 |
# Emit error for unknown model
|
| 711 |
return fastapi.responses.JSONResponse(
|
|
|
|
| 19 |
# Upstream pass-through
|
| 20 |
import httpx
|
| 21 |
|
| 22 |
+
from agents.code_writing_agents import (
|
| 23 |
generate_code_writing_agent_without_tools,
|
| 24 |
generate_code_writing_agent_with_search,
|
| 25 |
)
|
| 26 |
|
| 27 |
+
from agents.json_tool_calling_agents import (
|
| 28 |
+
generate_code_writing_agent_with_search_and_code,
|
| 29 |
+
generate_self_critiquing_agent,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
# Logging setup
|
| 33 |
logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO").upper())
|
| 34 |
log = logging.getLogger(__name__)
|
|
|
|
| 625 |
return {
|
| 626 |
"object": "list",
|
| 627 |
"data": [
|
| 628 |
+
{
|
| 629 |
+
"id": "self-critiquing-agent",
|
| 630 |
+
"object": "model",
|
| 631 |
+
"created": now,
|
| 632 |
+
"owned_by": "you",
|
| 633 |
+
},
|
| 634 |
+
{
|
| 635 |
+
"id": "tool-calling-agent-with-search-and-code",
|
| 636 |
+
"object": "model",
|
| 637 |
+
"created": now,
|
| 638 |
+
"owned_by": "you",
|
| 639 |
+
},
|
| 640 |
{
|
| 641 |
"id": "code-writing-agent-without-tools",
|
| 642 |
"object": "model",
|
| 643 |
"created": now,
|
| 644 |
"owned_by": "you",
|
|
|
|
| 645 |
},
|
| 646 |
{
|
| 647 |
"id": "code-writing-agent-with-search",
|
|
|
|
| 722 |
agent_for_request = generate_code_writing_agent_without_tools()
|
| 723 |
elif model_name == "code-writing-agent-with-search":
|
| 724 |
agent_for_request = generate_code_writing_agent_with_search()
|
| 725 |
+
elif model_name == "tool-calling-agent-with-search-and-code":
|
| 726 |
+
|
| 727 |
+
agent_for_request = generate_code_writing_agent_with_search_and_code()
|
| 728 |
+
elif model_name == "self-critiquing-agent":
|
| 729 |
+
|
| 730 |
+
agent_for_request = generate_self_critiquing_agent()
|
| 731 |
else:
|
| 732 |
# Emit error for unknown model
|
| 733 |
return fastapi.responses.JSONResponse(
|