Test agent with a simple file creation task.
()
| 14 | |
| 15 | @pytest.mark.asyncio |
| 16 | async def test_agent_simple_task(): |
| 17 | """Test agent with a simple file creation task.""" |
| 18 | print("\n=== Testing Agent with Simple File Task ===") |
| 19 | |
| 20 | # Load config |
| 21 | config_path = Path("mini_agent/config/config.yaml") |
| 22 | config = Config.from_yaml(config_path) |
| 23 | |
| 24 | # Create temp workspace |
| 25 | with tempfile.TemporaryDirectory() as workspace_dir: |
| 26 | print(f"Using workspace: {workspace_dir}") |
| 27 | |
| 28 | # Load system prompt (Agent will auto-inject workspace info) |
| 29 | system_prompt_path = Path("mini_agent/config/system_prompt.md") |
| 30 | if system_prompt_path.exists(): |
| 31 | system_prompt = system_prompt_path.read_text(encoding="utf-8") |
| 32 | else: |
| 33 | system_prompt = "You are a helpful AI assistant that can use tools." |
| 34 | |
| 35 | # Initialize LLM client |
| 36 | llm_client = LLMClient( |
| 37 | api_key=config.llm.api_key, |
| 38 | api_base=config.llm.api_base, |
| 39 | model=config.llm.model, |
| 40 | ) |
| 41 | |
| 42 | # Initialize tools |
| 43 | tools = [ |
| 44 | ReadTool(workspace_dir=workspace_dir), |
| 45 | WriteTool(workspace_dir=workspace_dir), |
| 46 | EditTool(workspace_dir=workspace_dir), |
| 47 | BashTool(), |
| 48 | ] |
| 49 | |
| 50 | # Create agent |
| 51 | agent = Agent( |
| 52 | llm_client=llm_client, |
| 53 | system_prompt=system_prompt, |
| 54 | tools=tools, |
| 55 | max_steps=10, # Limit steps for testing |
| 56 | workspace_dir=workspace_dir, |
| 57 | ) |
| 58 | |
| 59 | # Task: Create a simple text file |
| 60 | task = "Create a file named 'test.txt' with the content 'Hello from Agent!'" |
| 61 | print(f"\nTask: {task}\n") |
| 62 | |
| 63 | agent.add_user_message(task) |
| 64 | |
| 65 | try: |
| 66 | result = await agent.run() |
| 67 | |
| 68 | print(f"\n{'=' * 80}") |
| 69 | print(f"Agent Result: {result}") |
| 70 | print("=" * 80) |
| 71 | |
| 72 | # Check if file was created |
| 73 | test_file = Path(workspace_dir) / "test.txt" |