MCPcopy Create free account
hub / github.com/MiniMax-AI/Mini-Agent / demo_file_creation

Function demo_file_creation

examples/02_simple_agent.py:19–112  ·  view source on GitHub ↗

Demo: Agent creates a file based on user request.

()

Source from the content-addressed store, hash-verified

17
18
19async def demo_file_creation():
20 """Demo: Agent creates a file based on user request."""
21 print("\n" + "=" * 60)
22 print("Demo: Agent-Driven File Creation")
23 print("=" * 60)
24
25 # Load configuration
26 config_path = Path("mini_agent/config/config.yaml")
27 if not config_path.exists():
28 print("❌ config.yaml not found. Please set up your API key first.")
29 print(" Run: cp mini_agent/config/config-example.yaml mini_agent/config/config.yaml")
30 return
31
32 config = Config.from_yaml(config_path)
33
34 # Check API key
35 if not config.llm.api_key or config.llm.api_key.startswith("YOUR_"):
36 print("❌ API key not configured in config.yaml")
37 return
38
39 # Create temporary workspace
40 with tempfile.TemporaryDirectory() as workspace_dir:
41 print(f"📁 Workspace: {workspace_dir}\n")
42
43 # Load system prompt (Agent will auto-inject workspace info)
44 system_prompt_path = Path("mini_agent/config/system_prompt.md")
45 if system_prompt_path.exists():
46 system_prompt = system_prompt_path.read_text(encoding="utf-8")
47 else:
48 system_prompt = "You are a helpful AI assistant that can use tools."
49
50 # Initialize LLM client
51 llm_client = LLMClient(
52 api_key=config.llm.api_key,
53 api_base=config.llm.api_base,
54 model=config.llm.model,
55 )
56
57 # Initialize tools
58 tools = [
59 ReadTool(workspace_dir=workspace_dir),
60 WriteTool(workspace_dir=workspace_dir),
61 EditTool(workspace_dir=workspace_dir),
62 BashTool(),
63 ]
64
65 # Create agent
66 agent = Agent(
67 llm_client=llm_client,
68 system_prompt=system_prompt,
69 tools=tools,
70 max_steps=10,
71 workspace_dir=workspace_dir,
72 )
73
74 # Task: Create a Python hello world file
75 task = """
76 Create a Python file named 'hello.py' that:

Callers 1

mainFunction · 0.85

Calls 9

add_user_messageMethod · 0.95
runMethod · 0.95
LLMClientClass · 0.90
ReadToolClass · 0.90
WriteToolClass · 0.90
EditToolClass · 0.90
BashToolClass · 0.90
AgentClass · 0.90
from_yamlMethod · 0.80

Tested by

no test coverage detected