Spaces:
Sleeping
Sleeping
| import os | |
| import smolagents | |
| import smolagents.models | |
| def generate_code_writing_agent_with_tools( | |
| tools=None, | |
| name: str = "code_writing_agent_without_tools", | |
| description: str = "A code-writing agent without specialized tools.", | |
| ): | |
| """ | |
| Create a code-writing agent wwith a specific set of tools (defaults to none) | |
| """ | |
| if tools is None: | |
| tools = [] | |
| return smolagents.CodeAgent( | |
| name=name, | |
| description=description, | |
| model=smolagents.models.OpenAIServerModel( | |
| model_id=os.getenv("AGENT_MODEL", ""), | |
| api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"), | |
| api_key=os.getenv("OPENAI_API_KEY"), | |
| ), | |
| tools=tools, | |
| add_base_tools=False, | |
| max_steps=4, | |
| verbosity_level=int( | |
| os.getenv("AGENT_VERBOSITY", "1") | |
| ), # quieter by default; override via env | |
| ) | |
| def generate_code_writing_agent_without_tools(): | |
| """ | |
| Create a code-writing agent without any extra tools. | |
| """ | |
| return generate_code_writing_agent_with_tools() | |
| def generate_code_writing_agent_with_search(): | |
| """ | |
| Create a code-writing agent with search tools. | |
| """ | |
| tools = [smolagents.WebSearchTool(max_results=5)] | |
| return generate_code_writing_agent_with_tools( | |
| tools, | |
| name="code_writing_agent_with_search", | |
| description="A code-writing agent with search tools.", | |
| ) | |