MVP / Backend /executor /executor.py
github-actions[bot]
Deploy application
1f0fa9b
Raw History Blame Contribute Delete
1.7 kB
from schemas.agent_spec import AgentSpec
from .context import ExecutorContext
from tools.query_tool import run_query_tool
from tools.summarize_tool import run_summarize_tool
# Tool registry linking spec names to python functions
TOOLS = {
"query_tool": run_query_tool,
"summarize_tool": run_summarize_tool
}
def execute_spec(spec: AgentSpec) -> list:
"""
Executes the given AgentSpec synchronously.
Returns a log list detailing execution.
"""
context = ExecutorContext()
log = []
log.append(f"Starting execution of Agent: {spec.name}")
log.append(f"Description: {spec.description}")
for step in spec.steps:
tool_name = step.tool.name
raw_params = step.tool.parameters
if tool_name not in TOOLS:
log.append(f"Step '{step.id}' FAILED: Unknown tool '{tool_name}' installed in runner.")
break
log.append(f"--> Running Step '{step.id}': {step.description}")
# Resolve any dependency outputs in parameters using context
try:
resolved_params = context.resolve_dict(raw_params)
except Exception as e:
log.append(f"Step '{step.id}' FAILED during parameter resolution: {e}")
break
# Execute tool
try:
tool_func = TOOLS[tool_name]
result = tool_func(resolved_params)
context.set_output(step.id, result)
log.append(f"<-- Output of '{step.id}':\n{result}")
except Exception as e:
log.append(f"Step '{step.id}' FAILED during execution: {e}")
break
log.append("Execution Complete.")
return log