-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (39 loc) · 1.55 KB
/
main.py
File metadata and controls
51 lines (39 loc) · 1.55 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
"""05_hooks — Hooks.
Demonstrates a custom FingerprintHook, MaxToolCallsGuard, and ToolNameSanitizer
(strips model-injected artifacts from tool names), all declared inline in config.yaml.
Usage:
uv run python examples/05_hooks/main.py
"""
from __future__ import annotations
from pathlib import Path
CONFIG = Path(__file__).parent / "config.yaml"
STARTER = "Research the impact of electric vehicles on city air quality. Be thorough."
def main() -> None:
from strands_compose import load
resolved = load(CONFIG)
agent = resolved.entry
print(f"\n{52 * '-'}")
print(f"Try: {STARTER}\n")
print(
"Watch for the CUSTOM HOOK summary line after each response — that's FingerprintHook counting tool calls."
)
print("MaxToolCallsGuard will stop the agent after 5 tool calls.")
print("Type a message and press Enter. Empty line to exit.\n")
try:
while True:
msg = input("You: ").strip()
if not msg:
break
print("\nAgent is thinking...")
result = agent(msg)
print(f"\n\n{52 * '-'}")
print(f"Agent: {result}\n")
except KeyboardInterrupt:
print("\nGoodbye!")
finally:
resolved.mcp_lifecycle.stop()
# ── entry point ───────────────────────────────────────────────────────────────
if __name__ == "__main__":
from strands_compose import cli_errors
with cli_errors():
main()