-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_factory.py
More file actions
71 lines (56 loc) · 2.13 KB
/
agent_factory.py
File metadata and controls
71 lines (56 loc) · 2.13 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import re
class AgentFactory:
"""Generates Agent Configurations from high-level intent."""
@staticmethod
def create_team_config(intent: str, team_id: str = None) -> str:
"""
Generate a JSON configuration for an agent team based on intent.
Args:
intent: The high-level goal (e.g. "Research Windfield")
team_id: Optional ID for the team/agent
Returns:
JSON string configuration
"""
if not team_id:
# Generate ID from intent
clean_intent = re.sub(r"[^a-zA-Z0-9]", "_", intent.lower())
team_id = f"team_{clean_intent[:30]}"
# For now, we create a single "Team Leader" agent that represents the team.
# In the future, this could generate multiple YAMLs.
# Simple template for a generic "Task Agent"
config = {
"id": team_id,
"name": f"Agent Team: {intent}",
"description": f"Team dedicated to: {intent}",
"schedule": "0 8 * * *", # Default to daily at 8am
"script": AgentFactory._generate_script(intent),
}
return json.dumps(config, indent=2)
@staticmethod
def _generate_script(intent: str) -> str:
"""Generate the Python script for the agent."""
# In a real implementation, this might use an LLM to generate code.
# For now, we use a template that prints the intent.
return f'''
import structlog
logger = structlog.get_logger()
def run(context):
"""
Auto-generated agent script for: {intent}
"""
logger.info("dynamic_agent_start", intent="{intent}")
print(f"[{intent}] Agent Team Executing...")
# 1. Access Context
last_run = context.get("last_run")
# 2. Perform Work (Simulation)
# TODO: Connect to real tool execution here
print(f"[{intent}] Analyzing workspace...")
print(f"[{intent}] Generating report...")
logger.info("dynamic_agent_complete", intent="{intent}")
return {{
"status": "success",
"message": "Executed work for: {intent}",
"data": {{ "intent": "{intent}", "artifacts": [] }}
}}
'''