MCPcopy
hub / github.com/zai-org/Open-AutoGLM / example_with_callbacks

Function example_with_callbacks

examples/basic_usage.py:44–70  ·  view source on GitHub ↗

Task example with callbacks / 带回调的任务示例

(lang: str = "cn")

Source from the content-addressed store, hash-verified

42
43
44def example_with_callbacks(lang: str = "cn"):
45 """Task example with callbacks / 带回调的任务示例"""
46 msgs = get_messages(lang)
47
48 def my_confirmation(message: str) -> bool:
49 """Sensitive operation confirmation callback / 敏感操作确认回调"""
50 print(f"\n[{msgs['confirmation_required']}] {message}")
51 response = input(f"{msgs['continue_prompt']}: ")
52 return response.lower() in ("yes", "y", "是")
53
54 def my_takeover(message: str) -> None:
55 """Manual takeover callback / 人工接管回调"""
56 print(f"\n[{msgs['manual_operation_required']}] {message}")
57 print(msgs["manual_operation_hint"])
58 input(f"{msgs['press_enter_when_done']}: ")
59
60 # Create Agent with custom callbacks
61 agent_config = AgentConfig(lang=lang)
62 agent = PhoneAgent(
63 agent_config=agent_config,
64 confirmation_callback=my_confirmation,
65 takeover_callback=my_takeover,
66 )
67
68 # Execute task that may require confirmation
69 result = agent.run("打开淘宝搜索无线耳机并加入购物车")
70 print(f"{msgs['task_result']}: {result}")
71
72
73def example_step_by_step(lang: str = "cn"):

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
get_messagesFunction · 0.90
AgentConfigClass · 0.90
PhoneAgentClass · 0.90

Tested by

no test coverage detected