Repository navigation
Expand file tree
/
Copy pathagent.py
More file actions
59 lines (48 loc) · 1.95 KB
/
Copy pathagent.py
File metadata and controls
59 lines (48 loc) · 1.95 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
#!/usr/bin/env python3
"""Plain-Python agent that asks Agent Taskbay to approve one action.
Run it, then connect ``/.well-known/agent-card.json`` (or ``/card.json``) in the
console. The first message on a task opens an approval. A later message completes
the task only when it carries ``metadata.approval`` whose digest matches the
approved text. A chat reply leaves the task waiting. Rejecting in the console
sends no message.
"""
import sys
try:
from agent_taskbay import AgentCard, AgentServer, Skill
except ImportError:
sys.stderr.write(
"This example needs the experimental helper, which is not on PyPI.\n"
"From a checkout of this repository:\n"
" pip install -e ../../sdk/python\n"
)
raise SystemExit(1)
APPROVED_TEXT = "Apply migration: CREATE INDEX CONCURRENTLY idx_audit_created ON audit_logs(created_at);"
def main() -> None:
port = int(sys.argv[1]) if len(sys.argv) > 1 else 5050
card = AgentCard(
name="Python Ops Agent",
description="Asks a person to approve a database migration before doing anything else.",
skills=[
Skill(
id="migrate-database",
name="Database migration",
description="Proposes a schema migration and waits for an approval.",
tags=["ops", "database"],
examples=["migrate the audit log index"],
)
],
)
server = AgentServer(card, host="127.0.0.1", port=port)
@server.on_task
def handle(_task_id: str, message: str, operator):
asked = message or "(empty)"
return operator.request_approval(
"Production database schema migration",
APPROVED_TEXT,
summary=f"Operator said: {asked}. Create an index on audit_logs(created_at). Nothing runs until this exact text is approved.",
risk="high",
expires_in_seconds=3600,
)
server.start()
if __name__ == "__main__":
main()