PrefectHQ / ControlFlow

🦾 Take control of your AI agents
https://controlflow.ai
Apache License 2.0
769 stars 55 forks source link

Example code in the Documentation Doesn't work #316

Closed kingabzpro closed 2 months ago

kingabzpro commented 2 months ago

Description

I was trying to run sample code from examples and getting started and I am getting the same error. Maybe I am missing something or the docs.

10:52:55.567 | ERROR   | Task run 'Agent turn: Marvin' - Task run failed with exception: ValueError('Agent Marvin: No model provided and no default model could be loaded.') - Retries are exhausted

Example Code

import controlflow as cf

@cf.flow
def analyze_text(text: str):

    # Create a parent task to represent the entire analysis
    with cf.Task(
        "Analyze the given text", 
        instructions="Include each subtask result in your result",
        result_type=dict, 
        context={"text": text}
    ) as parent_task:

        # Child task 1: Identify key terms
        key_terms = cf.Task(
            "Identify up to 10 key terms in the text",
            result_type=list[str]
        )

        # Child task 2: Summarize (depends on key_terms)
        summary = cf.Task(
            "Summarize the text in one sentence",
            result_type=str,
            depends_on=[key_terms]
        )

    # Run the parent task, which will automatically run all child tasks
    result = parent_task.run()
    return result

# Execute the flow
text = """
    Agentic workflow orchestration refers to the coordination of autonomous
    agents within a structured workflow, allowing them to operate independently
    while achieving a common objective. Unlike traditional workflows that rigidly
    define tasks and dependencies, agentic workflows empower agents—typically
    AI-driven—to make decisions, prioritize tasks, and collaborate dynamically.
    Each agent in this system operates with a degree of autonomy, enabling it to
    adapt to changing conditions, handle uncertainties, and optimize its own
    actions within the broader workflow. This approach enhances flexibility and
    scalability, making it particularly effective for complex, multi-step
    processes where real-time adjustments and intelligent decision-making are
    crucial. By leveraging agents with defined roles and responsibilities, agentic
    workflows maintain structure while enabling innovation and responsiveness in
    task execution.
    """

result = analyze_text(text)
print(result)

Version Information

ControlFlow version: 0.9.3                              
       Prefect version: 3.0.2                              
LangChain Core version: 0.3.1                              
        Python version: 3.10.12                            
              Platform: Linux-6.1.85+-x86_64-with-glibc2.35
                  Path: /usr/local/lib/python3.10

Additional Context

No response

jlowin commented 2 months ago

The error message says that the default model could not be configured. It is likely that there is an earlier error message that says something like:

07:07:42.188 | WARNING | controlflow.llm.models - The default LLM model could not be created. 
ControlFlow will continue to work, but you must manually provide an LLM model for each agent. 
For more information, please see https://controlflow.ai/guides/llms. The error was:
1 validation error for ChatOpenAI
__root__
  Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which 
contains it, or pass `openai_api_key` as a named parameter. (type=value_error)

Is your OPENAI_API_KEY set, as described here (https://controlflow.ai/installation), or did you change the default LLM without providing full configuration?

The following simple script should run without error or warning if the OpenAI api key is provided:

import controlflow as cf

cf.run('hello')
kingabzpro commented 2 months ago

My bad. You are right.