Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Swarm registration of an agent's tools from their tools property #990

Merged
merged 7 commits into from
Feb 18, 2025

Conversation

marklysze
Copy link
Collaborator

@marklysze marklysze commented Feb 17, 2025

Why are these changes needed?

Reference agents are using a tools property and this was not being considered when creating a swarm so their tools were not registered with the internal tools executor and couldn't be executed.

This depends on #989.

Related issue number

Closes #988

Checks

Copy link

codecov bot commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Flag Coverage Δ
3.10 59.71% <ø> (+6.42%) ⬆️
3.11 57.26% <ø> (+2.58%) ⬆️
3.12 56.17% <ø> (+2.92%) ⬆️
3.13 59.29% <ø> (+6.33%) ⬆️
3.9 58.96% <ø> (+5.90%) ⬆️
anthropic 15.59% <ø> (?)
bedrock 15.94% <ø> (?)
browser-use 29.67% <ø> (-3.98%) ⬇️
cerebras 15.67% <ø> (?)
cohere 15.71% <ø> (?)
commsagent-discord 29.96% <ø> (?)
commsagent-slack 29.95% <ø> (?)
commsagent-telegram 29.90% <ø> (?)
crawl4ai 29.69% <ø> (-3.12%) ⬇️
docs 28.69% <ø> (?)
gemini 15.70% <ø> (?)
graph-rag-falkor-db 28.17% <ø> (?)
groq 15.69% <ø> (?)
interop 29.56% <ø> (-3.43%) ⬇️
interop-crewai 28.93% <ø> (?)
interop-langchain 28.76% <ø> (?)
interop-pydantic-ai 29.28% <ø> (?)
jupyter-executor 30.75% <ø> (?)
lmm 18.38% <ø> (?)
long-context 14.87% <ø> (?)
macos-latest 60.18% <ø> (+6.85%) ⬆️
mistral 15.41% <ø> (?)
ollama 16.06% <ø> (?)
retrievechat 29.67% <ø> (?)
retrievechat-couchbase 17.18% <ø> (?)
retrievechat-mongodb 29.66% <ø> (?)
retrievechat-pgvector 29.66% <ø> (?)
retrievechat-qdrant 29.61% <ø> (?)
teachable 15.03% <ø> (?)
together 15.73% <ø> (?)
twilio 28.39% <ø> (?)
ubuntu-latest 60.20% <ø> (+5.42%) ⬆️
websurfer 17.83% <ø> (?)
windows-latest 57.96% <ø> (+6.87%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 22 files with indirect coverage changes

@marklysze
Copy link
Collaborator Author

marklysze commented Feb 17, 2025

This now works successfully to browse the web and send a message to Discord:

import os

from autogen import AfterWork, AfterWorkOption, ConversableAgent, OnCondition, initiate_swarm_chat, register_hand_off
from autogen.agents.experimental import DiscordAgent, WebSurferAgent

# LLM configuration for our agent to select the tools and craft the message
llm_config = {"model": "gpt-4o-mini"}

triage_agent = ConversableAgent(
    name="triage_agent",
    llm_config=llm_config,
)

websurfer_agent = WebSurferAgent(
    name="websurfer_agent",
    llm_config=llm_config,
)

discord_agent = DiscordAgent(
    name="discord_agent",
    llm_config=llm_config,
    bot_token=os.getenv("DISCORD_BOT_TOKEN"),
    guild_name="My Discord Server",
    channel_name="general",
    is_termination_msg=lambda x: (x["content"] is not None) and "TERMINATE" in x["content"],
)

register_hand_off(
    agent=triage_agent,
    hand_to=[
        OnCondition(target=websurfer_agent, condition="Find information on the web."),
        OnCondition(
            target=discord_agent,
            condition="Send weather details to Discord only after you have received them.",
        ),
        AfterWork(AfterWorkOption.TERMINATE),
    ],
)

register_hand_off(agent=websurfer_agent, hand_to=[AfterWork(agent=triage_agent)])

register_hand_off(agent=discord_agent, hand_to=[AfterWork(agent=triage_agent)])

result, cv, last_agent = initiate_swarm_chat(
    initial_agent=triage_agent,
    agents=[triage_agent, discord_agent, websurfer_agent],
    messages="Find the latest weather for Sydney, NSW, Australia and post it on Discord",
    max_rounds=10,
)

@marklysze
Copy link
Collaborator Author

Screenshot 2025-02-17 at 11 10 54 am

@marklysze marklysze self-assigned this Feb 17, 2025
@marklysze marklysze requested a review from davorrunje February 17, 2025 00:13
@marklysze marklysze added the bug Something isn't working label Feb 17, 2025
@sonichi sonichi added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit dd4e414 Feb 18, 2025
466 of 485 checks passed
@sonichi sonichi deleted the swarmagenttools branch February 18, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug]: New reference agents don't get their tools registered when added to a Swarm
3 participants