MCPcopy Create free account
hub / github.com/HKUDS/AutoAgent / agent

Function agent

autoagent/cli.py:56–84  ·  view source on GitHub ↗

Run an agent with a given model, agent function, query, and context variables. Args: model (str): The name of the model. agent_func (str): The function to get the agent. query (str): The user query to the agent. context_variables (list): The context variables

(model: str, agent_func: str, query: str, context_variables)

Source from the content-addressed store, hash-verified

54@click.option('--query', default='...', help='the user query to the agent')
55@click.argument('context_variables', nargs=-1)
56def agent(model: str, agent_func: str, query: str, context_variables):
57 """
58 Run an agent with a given model, agent function, query, and context variables.
59 Args:
60 model (str): The name of the model.
61 agent_func (str): The function to get the agent.
62 query (str): The user query to the agent.
63 context_variables (list): The context variables to pass to the agent.
64 Usage:
65 mc agent --model=gpt-4o-2024-08-06 --agent_func=get_weather_agent --query="What is the weather in Tokyo?" city=Tokyo unit=C timestamp=2024-01-01
66 """
67 context_storage = {}
68 for arg in context_variables:
69 if '=' in arg:
70 key, value = arg.split('=', 1)
71 context_storage[key] = value
72 agent_module = importlib.import_module(f'autoagent.agents')
73 try:
74 agent_func = getattr(agent_module, agent_func)
75 except AttributeError:
76 raise ValueError(f'Agent function {agent_func} not found, you shoud check in the `autoagent.agents` directory for the correct function name')
77 agent = agent_func(model)
78 mc = MetaChain()
79 messages = [
80 {"role": "user", "content": query}
81 ]
82 response = mc.run(agent, messages, context_storage, debug=True)
83 debug_print(True, response.messages[-1]['content'], title = f'Result of running {agent.name} agent', color = 'pink3')
84 return response.messages[-1]['content']
85
86@cli.command()
87@click.option('--workflow_name', default=None, help='the name of the workflow')

Callers

nothing calls this directly

Calls 3

runMethod · 0.95
MetaChainClass · 0.90
debug_printFunction · 0.90

Tested by

no test coverage detected