MCPcopy Index your code
hub / github.com/AI45Lab/Code / main

Function main

sdk/python/examples/hitl_confirmation_loop.py:69–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67
68
69def main() -> None:
70 config_path = os.environ.get("A3S_CONFIG_FILE") or (sys.argv[1] if len(sys.argv) > 1 else None)
71 if not config_path:
72 raise RuntimeError("Set A3S_CONFIG_FILE or pass an agent.acl path as the first argument.")
73
74 workspace = os.environ.get("A3S_CODE_WORKSPACE") or os.getcwd()
75 prompt = os.environ.get("A3S_CODE_HITL_PROMPT") or (
76 "Use the bash tool to run: echo A3S_CODE_HITL_OK. Then summarize the result."
77 )
78
79 opts = SessionOptions()
80 opts.planning_mode = "disabled"
81 opts.permission_policy = PermissionPolicy(ask=["bash*"], default_decision="allow")
82 opts.confirmation_policy = ConfirmationPolicy(
83 enabled=True,
84 default_timeout_ms=120_000,
85 timeout_action="reject",
86 yolo_lanes=["query"],
87 )
88
89 agent = Agent.create(config_path)
90 session = agent.session(workspace, opts)
91
92 try:
93 for event in session.stream(prompt):
94 if event.event_type == "text_delta" and event.text:
95 print(event.text, end="", flush=True)
96 elif event.event_type == "tool_start":
97 print(f"\n[tool:start] {event.tool_name or 'unknown'}")
98 elif event.event_type == "tool_end":
99 print(f"\n[tool:end] {event.tool_name or 'unknown'} exit={event.exit_code or 0}")
100 elif event.event_type == "confirmation_required":
101 confirm_from_cli(session, event)
102 elif event.event_type == "confirmation_received":
103 print(f"\n[hitl] confirmation_received {event.tool_id or ''}")
104 elif event.event_type == "confirmation_timeout":
105 print(f"\n[hitl] confirmation_timeout {event.tool_id or ''}")
106 elif event.event_type == "error":
107 raise RuntimeError(event.error or "stream error")
108
109 print("\n[hitl] stream complete")
110 finally:
111 session.cancel_confirmations()
112
113
114if __name__ == "__main__":

Callers 1

Calls 9

confirm_from_cliFunction · 0.85
SessionOptionsClass · 0.50
PermissionPolicyClass · 0.50
ConfirmationPolicyClass · 0.50
getMethod · 0.45
createMethod · 0.45
sessionMethod · 0.45
streamMethod · 0.45
cancel_confirmationsMethod · 0.45

Tested by

no test coverage detected