ccm commited on
Commit
d604728
·
1 Parent(s): 1c34a6b

Adding an additional agent

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. agents/code_writing_agent.py +19 -2
  3. proxy.py +18 -7
Dockerfile CHANGED
@@ -15,7 +15,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
15
  RUN python3 -m pip install --no-cache-dir --upgrade pip && \
16
  pip3 install --no-cache-dir \
17
  fastapi uvicorn httpx[http2] \
18
- smolagents litellm \
19
  "pydantic>=2,<3"
20
 
21
  # MongoDB
 
15
  RUN python3 -m pip install --no-cache-dir --upgrade pip && \
16
  pip3 install --no-cache-dir \
17
  fastapi uvicorn httpx[http2] \
18
+ smolagents[toolkit] litellm \
19
  "pydantic>=2,<3"
20
 
21
  # MongoDB
agents/code_writing_agent.py CHANGED
@@ -3,10 +3,12 @@ import smolagents
3
  import smolagents.models
4
 
5
 
6
- def create_code_writing_agent():
7
  """
8
  Create a code-writing agent without any extra tools.
9
  """
 
 
10
  return smolagents.CodeAgent(
11
  name="code_writing_agent_without_tools",
12
  model=smolagents.models.OpenAIServerModel(
@@ -14,10 +16,25 @@ def create_code_writing_agent():
14
  api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
15
  api_key=os.getenv("OPENAI_API_KEY"),
16
  ),
17
- tools=[], # no extra tools
18
  add_base_tools=False,
19
  max_steps=4,
20
  verbosity_level=int(
21
  os.getenv("AGENT_VERBOSITY", "1")
22
  ), # quieter by default; override via env
23
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import smolagents.models
4
 
5
 
6
+ def generate_code_writing_agent_with_tools(tools=None):
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="code_writing_agent_without_tools",
14
  model=smolagents.models.OpenAIServerModel(
 
16
  api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
17
  api_key=os.getenv("OPENAI_API_KEY"),
18
  ),
19
+ tools=tools,
20
  add_base_tools=False,
21
  max_steps=4,
22
  verbosity_level=int(
23
  os.getenv("AGENT_VERBOSITY", "1")
24
  ), # quieter by default; override via env
25
  )
26
+
27
+
28
+ def generate_code_writing_agent_without_tools():
29
+ """
30
+ Create a code-writing agent without any extra tools.
31
+ """
32
+ return generate_code_writing_agent_with_tools()
33
+
34
+
35
+ def generate_code_writing_agent_with_search():
36
+ """
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(tools)
proxy.py CHANGED
@@ -19,7 +19,10 @@ import contextlib
19
  # Upstream pass-through
20
  import httpx
21
 
22
- from agents.code_writing_agent import create_code_writing_agent
 
 
 
23
 
24
  # Logging setup
25
  logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO").upper())
@@ -692,13 +695,21 @@ async def chat_completions(req: fastapi.Request):
692
  AGENT_MODEL,
693
  AGENT_MODEL + "-nothink",
694
  ) and isinstance(model_name, str):
695
- try:
696
- agent_for_request = create_code_writing_agent()
697
- except Exception:
698
- log.exception(
699
- "Failed to construct agent for model '%s'; using default", model_name
 
 
 
 
 
 
 
 
 
700
  )
701
- agent_for_request = None
702
 
703
  try:
704
  if stream:
 
19
  # Upstream pass-through
20
  import httpx
21
 
22
+ from agents.code_writing_agent import (
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())
 
695
  AGENT_MODEL,
696
  AGENT_MODEL + "-nothink",
697
  ) and isinstance(model_name, str):
698
+ if model_name == "code-writing-agent-without-tools":
699
+ agent_for_request = generate_code_writing_agent_without_tools()
700
+ elif model_name == "code-writing-agent-with-search":
701
+ agent_for_request = generate_code_writing_agent_with_search()
702
+ else:
703
+ # Emit error for unknown model
704
+ return fastapi.responses.JSONResponse(
705
+ status_code=400,
706
+ content={
707
+ "error": {
708
+ "message": f"Unknown model id: {model_name}",
709
+ "type": "invalid_request_error",
710
+ }
711
+ },
712
  )
 
713
 
714
  try:
715
  if stream: