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

Class StreamlitProgress

03-ai-agent-for-devops/code/14/app.py:47–92  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected