kyegomez / swarms

The Enterprise-Grade Production-Ready Multi-Agent Orchestration Framework Join our Community: https://discord.com/servers/agora-999382051935506503
https://docs.swarms.world
GNU Affero General Public License v3.0
1.74k stars 236 forks source link

Not able to agent with tool from example #476

Open vaidikcs opened 5 months ago

vaidikcs commented 5 months ago

i tried to run code from your example

@tool def search_api(query: str):

Add your logic here

return query

Initializing the agent with the OpenAI instance and other parameters

agent = Agent( agent_name="Covid-19-Chat", agent_description=( "This agent provides information about COVID-19 symptoms." ), llm=llm, max_loops="auto", autosave=True, verbose=True, stopping_condition="finish", tools=[search_api], )

Defining the task and image path

task = ("What are the symptoms of COVID-19?",)

Running the agent with the specified task and image

out = agent.run(task) print(out)

i got error

image

and one more thing is there any blog or something to see working of multi agents with tools.

Upvote & Fund

Fund with Polar

github-actions[bot] commented 5 months ago

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.

kyegomez commented 5 months ago

@vaidikcs try another llm like Anthropic or Llama3Hosted, this has a parsing error but it did run!

aimzieslol commented 4 months ago

@kyegomez @vaidikcs I'm having this problem as well using Groq with the OpenAIChat class. @tool definition looks like this:

@tool(name='dumb_string', return_string=True, return_dict=False)
def dumb_string(dumb_str: str):
    return f'this is dumb: {dumb_str}'

I've tried removing all params from @tool, different params, using just @tool(), etc.

Vits-99 commented 3 months ago

@kyegomez got same error here

kyegomez commented 3 months ago

@Vits-99 @aimzieslol @nictuku no more tool decorator is needed, just the function with types, and doc strings.

Vits-99 commented 3 months ago

@kyegomez thanks! But why running the Devin Example I get this error in tool parsing?

2024-07-21T11:16:58.305840+0200 Error parsing and executing JSON: Expecting value: line 1 column 1 (char 0)

Or anyway I get this after providing file name and content in the terminal after interaction even if the agent understand it should be using the create_file tool: Tool Call Output: {}

The code I am running is this:

from swarms import Agent, OpenAIChat
import subprocess

# Tools in swarms are simple python functions and docstrings
def terminal(
    code: str,
):
    """
    Run code in the terminal.

    Args:
        code (str): The code to run in the terminal.

    Returns:
        str: The output of the code.
    """
    out = subprocess.run(
        code, shell=True, capture_output=True, text=True
    ).stdout
    return str(out)

def browser(query: str):
    """
    Search the query in the browser with the `browser` tool.

    Args:
        query (str): The query to search in the browser.

    Returns:
        str: The search results.
    """
    import webbrowser

    url = f"https://www.google.com/search?q={query}"
    webbrowser.open(url)
    return f"Searching for {query} in the browser."

def create_file(file_path: str, content: str):
    """
    Create a file using the file editor tool.

    Args:
        file_path (str): The path to the file.
        content (str): The content to write to the file.

    Returns:
        str: The result of the file creation operation.
    """
    with open(file_path, "w") as file:
        file.write(content)
    return f"File {file_path} created successfully."

def file_editor(file_path: str, mode: str, content: str):
    """
    Edit a file using the file editor tool.

    Args:
        file_path (str): The path to the file.
        mode (str): The mode to open the file in.
        content (str): The content to write to the file.

    Returns:
        str: The result of the file editing operation.
    """
    with open(file_path, mode) as file:
        file.write(content)
    return f"File {file_path} edited successfully."

# Agent
agent = Agent(
    agent_name="Devin",
    system_prompt=(
        "Autonomous agent that can interact with humans and other"
        " agents. Be Helpful and Kind. Use the tools provided to"
        " assist the user. Return all code in markdown format."
    ),
    llm=OpenAIChat(model_name="gpt-4o-mini", openai_api_key="..."),
    max_loops="auto",
    autosave=True,
    dashboard=False,
    verbose=True,
    interactive=True,
    tools=[terminal, browser, file_editor, create_file],
    code_interpreter=True,
)

# Run the agent
out = agent("Create a new file for a plan to take over the world.")
print(out)

I can then interact with it but it is not able to use the tools. Any suggestion?