File size: 1,495 Bytes
40e2320 7d2c8ec 40e2320 f21aa99 70617f3 40e2320 70617f3 40e2320 c95c1a0 7d2c8ec c95c1a0 9d3cb6b 7d2c8ec c95c1a0 40e2320 7d2c8ec c95c1a0 40e2320 7d2c8ec 40e2320 c95c1a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import os
from smolagents import CodeAgent, DuckDuckGoSearchTool, GradioUI, InferenceClientModel, ManagedAgent
# 1. THE BRAIN
model = InferenceClientModel(
model_id="deepseek-ai/DeepSeek-R1",
token=os.getenv("HF_TOKEN")
)
# 2. THE RESEARCHER (Specialist)
# We wrap the researcher in ManagedAgent so the Boss can "call" it.
search_agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=model,
name="research_specialist",
description="Finds technical data and web information. Use for all research tasks."
)
managed_researcher = ManagedAgent(
agent=search_agent,
name="research_specialist",
description="A web-search specialist. Call this agent when you need current data from the internet."
)
# 3. THE BOSS LOGIC (The Template Fix)
# This dictionary overrides the read-only system_prompt property.
custom_templates = {
"system_prompt": """You are the BOSS OPERATOR (Elite PhD Level).
1. Delegate sub-tasks to 'research_specialist' for web-based data.
2. Use your internal Python tools for math, simulation, and data analysis.
3. Always verify data before presenting a final answer.
4. Format all math in LaTeX ($E=mc^2$) and all data in Markdown tables."""
}
# 4. THE BOSS (Manager)
manager = CodeAgent(
tools=[],
model=model,
managed_agents=[managed_researcher],
add_base_tools=True,
prompt_templates=custom_templates # <--- THIS IS THE CRITICAL FIX
)
if __name__ == "__main__":
GradioUI(manager).launch() |