run-llama / llama-agents

MIT License
1.6k stars 159 forks source link

AttributeError: 'function' object has no attribute 'launch_server' #133

Open DARK-art108 opened 1 month ago

DARK-art108 commented 1 month ago

This is my code , which is producing this error

queue_task = asyncio.create_task(self.message_queue.launch_server())
AttributeError: 'function' object has no attribute 'launch_server'
from llama_agents import (
    AgentService,
    HumanService,
    AgentOrchestrator,
    CallableMessageConsumer,
    ControlPlaneServer,
    ServerLauncher,
    SimpleMessageQueue,
    QueueMessage,
)
import os
from dotenv import dotenv_values
import json
from src.queues.smq import SMQ
env_config = dotenv_values(".env")
os.environ["MISTRAL_API_KEY"] = env_config["MISTRAL_API_KEY"]

config = json.load(open("config.json"))
if not config:
    raise Exception("Config file not found")

class Server:
    def __init__(self) -> None:
        self.llm = config.get("llm")
        self.agent_service = Services(llm=self.llm)

    def human_consumer(self):
        human_consumer = CallableMessageConsumer(handler=self.agent_service.result_handler, message_type="human")
        return human_consumer

    def server_launcher(self):
        agent_server_1,agent_server_2,human_service =  self.agent_service.agent_server()
        control_plane = self.agent_service.control_plane
        launcher = ServerLauncher(
                [agent_server_1, agent_server_2, human_service],
                control_plane,
                SMQ.smq_client,
                additional_consumers=[self.human_consumer()],
            )
        launcher.launch_servers()

if __name__ == "__main__":
    server = Server()
    server.server_launcher()

Any solution for this?

logan-markewich commented 1 month ago

I don't think SMQ.client is returning what you needed. I think it might be SMQ.client() ?

DARK-art108 commented 1 month ago

@logan-markewich Tried same still same error.

logan-markewich commented 1 month ago

Thats pretty sus. What is SMQ? Like what class?

logan-markewich commented 1 month ago

It's a property in the class that I think it is, so no brackets needed

https://github.com/run-llama/llama-agents/blob/de7ae001f983411b05a31bb733169ed6a7854d59/llama_agents/message_queues/simple.py#L209

logan-markewich commented 1 month ago

But for some reason for you, it's complaining that it's a function

DARK-art108 commented 1 month ago

Hi @logan-markewich this is my queue initialization

message_queue = SimpleMessageQueue()
queue_client = message_queue.client

And these are debug tracelogs :

Traceback (most recent call last):
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/riteshyadav/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/Users/riteshyadav/Desktop/llama-agents/server.py", line 49, in <module>
    server.server_launcher()
  File "/Users/riteshyadav/Desktop/llama-agents/server.py", line 45, in server_launcher
    launcher.launch_servers()
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/site-packages/llama_agents/launchers/server.py", line 100, in launch_servers
    return asyncio.run(self.alaunch_servers())
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/site-packages/llama_agents/launchers/server.py", line 111, in alaunch_servers
    control_plane_task = asyncio.create_task(self.control_plane.launch_server())
AttributeError: 'function' object has no attribute 'launch_server'
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<SimpleRemoteClientMessageQueue.launch_server() done, defined at /Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/site-packages/llama_agents/message_queues/simple.py:114> exception=NotImplementedError('`launch_server()` is not implemented for this class.')>
Traceback (most recent call last):
  File "/Users/riteshyadav/miniforge3/envs/genai/lib/python3.10/site-packages/llama_agents/message_queues/simple.py", line 115, in launch_server
    raise NotImplementedError(
NotImplementedError: `launch_server()` is not implemented for this class.
DARK-art108 commented 1 month ago

@logan-markewich any views onto above?

logan-markewich commented 1 month ago

@DARK-art108 I think you just need to update? pip install -U llama-agents