MCPcopy Create free account
hub / github.com/VersusControl/devops-ai-guidelines / StreamlitProgress

Class StreamlitProgress

03-ai-agent-for-devops/code/10/app.py:39–84  ·  view source on GitHub ↗

Callbacks that render live tool-call progress inside a st.status container.

Source from the content-addressed store, hash-verified

37
38
39class StreamlitProgress:
40 """Callbacks that render live tool-call progress inside a st.status container."""
41
42 def __init__(self, container):
43 self.status = container
44 self.tool_count = 0
45 self.steps = [] # saved into message history
46
47 def on_thinking(self):
48 self.status.update(label="Thinking...", state="running")
49
50 def on_reasoning(self, text: str):
51 if text:
52 self.status.write(f"_{text}_")
53 self.steps.append({"label": "Reasoning", "detail": text})
54
55 def on_tool_start(self, tool_name: str, tool_args: dict):
56 self.tool_count += 1
57 label = TOOL_LABELS.get(tool_name, tool_name)
58 self.status.update(label=f"{label}...", state="running")
59
60 def on_tool_end(self, tool_name: str, result: str, success: bool = True):
61 label = TOOL_LABELS.get(tool_name, tool_name)
62 marker = "OK" if success else "FAIL"
63 preview = _summarize_result(tool_name, result)
64 self.status.write(f"[{marker}] **{label}** — {preview}")
65 self.steps.append({"label": label, "detail": f"[{marker}] {preview}"})
66
67 def on_approval_skipped(self, tool_name: str, tool_args: dict):
68 label = TOOL_LABELS.get(tool_name, tool_name)
69 self.status.write(f"[BLOCKED] **{label}** — requires your approval")
70 self.steps.append({"label": label, "detail": "[BLOCKED] requires approval"})
71
72 def complete(self):
73 n = self.tool_count
74 if n:
75 self.status.update(
76 label=f"Done — {n} tool{'s' if n != 1 else ''} used",
77 state="complete", expanded=False,
78 )
79 else:
80 self.status.update(label="Done", state="complete", expanded=False)
81
82 def error(self, msg: str):
83 self.status.update(label="Error", state="error")
84 self.status.write(f"Error: {msg}")
85
86
87def _summarize_result(tool_name: str, result: str) -> str:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected