Build a cohesive runtime that plans dependent steps, dispatches tools, manages bounded working memory, applies guardrails, records a trace, and returns evaluation-ready output.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement run_agent_runtime(goal, config) that runs a complete agent lifecycle.
config is a dict with:
- planner (callable): generates a plan (planner(goal) returns list of step dicts with {"id": str, "tool": str, "params": any, "depends_on": list[str]}).
- tools (dict): tool name to callable mapping.
- max_steps (int): maximum execution steps.
- memory_limit (int): max entries in working memory.
- guardrails (list[callable]): each guardrail(step, context) returns True (allow) or False (block).
- approval_rules (dict): {tool_name: bool} where True means the step needs human approval.
Requirements:
- Start by calling the planner to generate a step plan.
- Execute plan steps considering dependencies (like the supervisor pattern).
- Before each step, check guardrails -- if any guardrail returns False, mark the step as blocked and continue.
- If a step's tool is in approval_rules and the rule is True, mark it as pending approval rather than executing immediately; simulate approval by setting a flag.
- Maintain a working memory dict (bounded by memory_limit) that stores results keyed by step ID.
- Record a trace: [{"step": str, "tool": str, "status": str, "result": any, "duration_ms": int}].
- If memory exceeds memory_limit, evict oldest entries (LRU-style).
- Return {"answer": str, "trace": list, "steps_completed": int, "memory_used": int, "blocked_steps": list[str]}.
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def run_agent_runtime(goal, config):
plan = config["planner"](goal)
trace = []
blocked = []
working_memory = {}
steps_completed = 0
memory_limit = config.get("memory_limit", 10)
tools = config["tools"]
guardrails = config.get("guardrails", [])
approval_rules = config.get("approval_rules", {})
max_steps = config.get("max_steps", 20)
completed = set()Execute plan with guardrails, approvals, bounded memory, and trace recording
answer = f"Completed {steps_completed} of {len(plan)} steps"
return {"answer": answer, "trace": trace, "steps_completed": steps_completed,
"memory_used": len(working_memory), "blocked_steps": blocked}Already have Pro access? Sign in