ControlFlow icon indicating copy to clipboard operation
ControlFlow copied to clipboard

Creating agents section of Core Concepts - Agents fails

Open bw-matthew opened this issue 1 year ago • 0 comments

Description

The example for the more complex agent fails to run because the controlflow.tools.web module and controlflow.tools.code module are not imported correctly. This is easy to miss because if you run two imports anywhere in your python environment then the example code will work.

The __init__.py file of the controlflow.tools module has the content:

from controlflow.tools.tools import tool, Tool, as_tools

There is no web or code here so the content of cf.tools is just

dir(cf.tools)

output:

['Tool',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'as_tools',
 'input',
 'tool',
 'tools']

So when you evaluate the expression cf.tools.web.get_url it results in the error AttributeError: module 'controlflow.tools' has no attribute 'web'. Equally if you evaluate the expression cf.tools.code.python it results in the error AttributeError: module 'controlflow.tools' has no attribute 'code'.

This should be fixed by adding the following imports to the example:

import controlflow.tools.web
import controlflow.tools.code

Example Code

import controlflow as cf

agent = cf.Agent(
    name="Data Analyst",
    description="An AI agent specialized in data analysis",
    instructions=(
        "Perform data analysis tasks efficiently and accurately. "
        "Browse the web for data and use Python to analyze it."
    ),
    tools=[cf.tools.web.get_url, cf.tools.code.python],
    model="openai/gpt-4o",
    interactive=True,
)

Version Information

ControlFlow version: 0.11.4
       Prefect version: 3.1.13
LangChain Core version: 0.3.30
        Python version: 3.12.7
              Platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39

Additional Context

No response

bw-matthew avatar Jan 20 '25 12:01 bw-matthew