Open lz-chen opened 1 month ago
Interesting, thanks for sharing @lz-chen.
@logan-markewich do you think perhaps AzureOpenAI as an orchestrator is not able to register the agent services as tools?
@lz-chen: I noticed in the logs that a ToolService wasn't registered. Are you instead following this example instead of the one you have originally linked?
Hi @nerdai indeed, I posted wrong link. Thank you for pointing out. What I have experienced is with this example. Here is my script:
from llama_agents import (
AgentService,
ControlPlaneServer,
SimpleMessageQueue,
PipelineOrchestrator,
ServiceComponent,
LocalLauncher,
)
from llama_agents.tools import ServiceAsTool
from llama_index.core.agent import FunctionCallingAgentWorker
from llama_index.core.tools import FunctionTool
from llama_index.core.query_pipeline import QueryPipeline
from llama_index.llms.azure_openai import AzureOpenAI
from llama_index.llms.openai import OpenAI
from llama_index.agent.openai import OpenAIAgent
from llama_index.core.settings import Settings
from web_scraping_agent.llm.base import llm_gpt4o
from web_scraping_agent.utils.config import settings
from llama_index.core.agent import ReActAgent
Settings.llm = llm_gpt4o
llm_gpt4o = AzureOpenAI(
azure_deployment=settings.AZURE_OPENAI_GPT4O_MODEL,
temperature=0.,
azure_endpoint=settings.AZURE_OPENAI_ENDPOINT,
api_key=settings.AZURE_OPENAI_API_KEY,
api_version=settings.AZURE_OPENAI_API_VERSION,
)
# create an agent
def get_the_secret_fact() -> str:
"""Returns the secret fact."""
return "The secret fact is: A baby llama is called a 'Cria'."
tool = FunctionTool.from_defaults(fn=get_the_secret_fact)
worker1 = FunctionCallingAgentWorker.from_tools([tool], llm=OpenAI())
# worker2 = FunctionCallingAgentWorker.from_tools([], llm=OpenAI())
agent1 = worker1.as_agent()
# create our multi-agent framework components
message_queue = SimpleMessageQueue()
agent1_server = AgentService(
agent=agent1,
message_queue=message_queue,
description="Useful for getting the secret fact.",
service_name="secret_fact_agent",
)
agent1_server_tool = ServiceAsTool.from_service_definition(
message_queue=message_queue, service_definition=agent1_server.service_definition
)
# agent2 = OpenAIAgent.from_tools(
# [agent1_server_tool],
# system_prompt="Perform the task, return the result as well as a funny joke.",
# ) # worker2.as_agent()
agent2 = ReActAgent.from_tools([agent1_server_tool],
llm=llm_gpt4o, verbose=True)
agent2_server = AgentService(
agent=agent2,
message_queue=message_queue,
description="Useful for telling funny jokes.",
service_name="dumb_fact_agent",
)
print(agent1_server.service_definition)
print(agent2_server.service_definition)
agent2_component = ServiceComponent.from_service_definition(agent2_server.service_definition)
pipeline = QueryPipeline(chain=[agent2_component])
pipeline_orchestrator = PipelineOrchestrator(pipeline)
control_plane = ControlPlaneServer(message_queue, pipeline_orchestrator)
# launch it
launcher = LocalLauncher([agent1_server, agent2_server], control_plane, message_queue)
result = launcher.launch_single("What is the secret fact?")
print(f"Result: {result}")
Thanks @lz-chen. Do you mind letting me know which version of llama-agents you're running?
I'm using version 0.0.9 @nerdai
That's bizarre. For some reason the tool name should be secret_fact_agent-as-tool
but ReActAgent is looking for secret_fact_agent
instead 🤔
Hmm shouldn't the ReActAgent be looking for secret_fact_agent
since that's the "tool" that agent1 expose as?
Also in the log it says:
INFO:llama_agents.message_queues.simple - Consumer AgentService-c6353956-4c98-4544-8c5b-321951f0aebc: secret_fact_agent has been registered.
Yeah so in this example, what we're doing is actually wrapping agent1
(more speicifically its service) as a tool so that agent2
can call it directly.
# here we make agent1 service a tool (the tool is now name f"{service.name}-as-tool" thus 'secret_fact_agent-as-tool')
agent1_server_tool = ServiceAsTool.from_service_definition(
message_queue=message_queue, service_definition=agent1_server.service_definition
)
# here we give the tool to agent2
agent2 = ReActAgent.from_tools([agent1_server_tool],
llm=llm_gpt4o, verbose=True)
# here we establish a pipeline that consists of only agent2 component
# meaning if agent1 service is called, the only way must be a tool call from agent2
pipeline = QueryPipeline(chain=[agent2_component])
I'll try to replicate the bug you're experiencing on my end tmr (likely in the evening). Will let you know how it goes
Thank you! @nerdai
Hi! I was following this example. I use Azure OpenAI and when I specify the
llm
inOpenAIAgent
to be anAzureOpenAI
instance, I keep getting connection error:And I changed
OpenAIAgent
toReActAgent
with the sameAzureOpenAI
instance, it's not able to find the registered agent as tool:Any suggestion on how I can fix this?