Skip to main content
Loading navigation

Implement AutoGen Agents with Claude Opus 4.1 & Tools

Prompt source

implementation38 lines8 sectionsNo variables1 code block
Write the Python code to initialize your AutoGen agents (e.g., UserProxyAgent, AssistantAgent with Claude Opus 4.1). Implement two custom AutoGen tools: one for fetching simulated CRE market data (e.g., `get_market_data(location, property_type)`) and another for performing basic financial calculations (e.g., `calculate_roi(cost, revenue)`). Ensure Claude Opus 4.1 is properly configured for the AssistantAgent and that tools are callable within the agent's context. 

```python
import autogen

# Configure Claude Opus 4.1
config_list_claude = [
    {
        "model": "claude-3-opus-20240229", # or equivalent API name for Claude Opus 4.1 via Azure/Anthropic
        "api_key": "YOUR_CLAUDE_API_KEY"
    }
]

# Define custom tools
def get_market_data(location: str, property_type: str) -> str:
    # Simulate API call
    if location == "Austin, TX" and property_type == "retail":
        return "Simulated Austin retail data: avg_yield=0.05, growth_potential=0.03"
    return "No data found for specified parameters."

def calculate_roi(cost: float, revenue: float) -> float:
    return (revenue - cost) / cost

# Create agents
# analyst_agent = autogen.AssistantAgent(
#    name="Analyst",
#    llm_config={"config_list": config_list_claude},
#    system_message="You are a commercial real estate analyst. Use tools to gather data and perform calculations."
# )
# user_proxy = autogen.UserProxyAgent(
#    name="User_Proxy",
#    human_input_mode="NEVER",
#    max_consecutive_auto_reply=10,
#    is_termination_msg=lambda x: "FINISH" in x.get("content", ""),
#    code_execution_config={"work_dir": "coding", "use_docker": False},
#    tool_code_extraction_config={"tool_code_block_tag": "tool_code"}
# )

# user_proxy.register_for_execution(get_market_data)
# user_proxy.register_for_llm(get_market_data)
# user_proxy.register_for_execution(calculate_roi)
# user_proxy.register_for_llm(calculate_roi)

# (Initialize GroupChat and run conversation)
```