-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_observability.py
More file actions
35 lines (28 loc) · 992 Bytes
/
Copy pathagent_observability.py
File metadata and controls
35 lines (28 loc) · 992 Bytes
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
"""A runnable day-one observability path for an LLM agent."""
import infrai_observability as infrai
def run_tool(agent, tool_name, tool):
"""Count a tool run and capture its exception with agent context."""
infrai.metrics.report(
type="counter", name="agent.tool.started", value=1,
tags={"agent": agent, "tool": tool_name},
)
try:
result = tool()
except Exception as exc:
infrai.errors.capture(
message=f"{agent}/{tool_name}: {exc}",
level="error",
exception=__import__("traceback").format_exc(),
context={"agent": agent, "step": tool_name},
)
raise
infrai.metrics.report(
type="counter", name="agent.tool.succeeded", value=1,
tags={"agent": agent, "tool": tool_name},
)
return result
def main():
answer = run_tool("research-agent", "local-answer", lambda: "observability chosen")
print(answer)
if __name__ == "__main__":
main()