test_micro_agents.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import json
  2. import os
  3. from unittest.mock import MagicMock
  4. import yaml
  5. from agenthub.micro.registry import all_microagents
  6. from opendevin.agent import Agent
  7. from opendevin.plan import Plan
  8. from opendevin.state import State
  9. def test_all_agents_are_loaded():
  10. full_path = os.path.join('agenthub', 'micro')
  11. agent_names = set()
  12. for root, _, files in os.walk(full_path):
  13. for file in files:
  14. if file == 'agent.yaml':
  15. file_path = os.path.join(root, file)
  16. with open(file_path, 'r') as yaml_file:
  17. data = yaml.safe_load(yaml_file)
  18. agent_names.add(data['name'])
  19. assert agent_names == set(all_microagents.keys())
  20. def test_coder_agent_with_summary():
  21. """
  22. Coder agent should render code summary as part of prompt
  23. """
  24. mock_llm = MagicMock()
  25. content = json.dumps({'action': 'finish', 'args': {}})
  26. mock_llm.completion.return_value = {
  27. 'choices': [{'message': {'content': content}}]
  28. }
  29. coder_agent = Agent.get_cls('CoderAgent')(llm=mock_llm)
  30. assert coder_agent is not None
  31. task = 'This is a dummy task'
  32. plan = Plan(task)
  33. summary = 'This is a dummy summary about this repo'
  34. state = State(plan, inputs={'summary': summary})
  35. coder_agent.step(state)
  36. mock_llm.completion.assert_called_once()
  37. _, kwargs = mock_llm.completion.call_args
  38. prompt = kwargs['messages'][0]['content']
  39. assert task in prompt
  40. assert "Here's a summary of the codebase, as it relates to this task" in prompt
  41. assert summary in prompt
  42. def test_coder_agent_without_summary():
  43. """
  44. When there's no codebase_summary available, there shouldn't be any prompt
  45. about 'code summary'
  46. """
  47. mock_llm = MagicMock()
  48. content = json.dumps({'action': 'finish', 'args': {}})
  49. mock_llm.completion.return_value = {
  50. 'choices': [{'message': {'content': content}}]
  51. }
  52. coder_agent = Agent.get_cls('CoderAgent')(llm=mock_llm)
  53. assert coder_agent is not None
  54. task = 'This is a dummy task'
  55. plan = Plan(task)
  56. state = State(plan)
  57. coder_agent.step(state)
  58. mock_llm.completion.assert_called_once()
  59. _, kwargs = mock_llm.completion.call_args
  60. prompt = kwargs['messages'][0]['content']
  61. assert task in prompt
  62. assert "Here's a summary of the codebase, as it relates to this task" not in prompt