Tracer-Cloud/opensre is an open-source CLI agent for CI/CD reliability (Apache 2.0, public alpha per its README). This post is a source reading at commit ccb1349: I cloned the repo and read core/agent/, core/tool/, docs/ARCHITECTURE.md, AGENTS.md and the CI/CD docs. Facts come from that code; interpretation is marked.
Companion tutorial: how to install and use it is on Cui.Guru: Fix red CI with the OpenSRE agent.
The workflow in motion
Architecture
The code base is seven first-party packages in four tiers. docs/ARCHITECTURE.md states the rule: higher tiers may import lower ones, never the reverse, and “these dependency rules are CI-enforced (make check-imports)”. surfaces and gateway are hosts; tools and integrations are peers that must not import each other; core and infrastructure may cross-import; config imports nothing first-party.
A consequence the doc spells out: since hosts cannot import each other and tools/integrations cannot import each other, each capability package registers itself and each host names the registrars once, in CAPABILITY_REGISTRARS.
Inside core, one turn looks like this:
(Conceptual diagram: member names drop the leading underscores used in the source.)
The core design idea
The loop is a small state machine that is deliberately blind to who runs it. The module docstring says it “knows nothing about Agent”: it takes an AgentRunInput and a LoopHost, so “anything implementing that host can drive it”. The host contract is a Protocol of a handful of callbacks: filter tools, emit events, drain steering messages, pop a queued follow-up, and decide whether a no-tool reply may end the turn. My reading: that last hook is where a goal check plugs in without the loop learning about goals.
The second idea is that the loop distrusts itself. It does not rely on the model to stop. In core/agent/react_loop.py an iteration ends the run in several distinct ways, each with its own stop_reason:
- the
for iteration in range(self._max_iterations)ceiling, followed by a “safety handoff” call with tools disabled; -
stagnation_limit, when the same tool calls produce an already-seen observation fingerprint too many times; -
discovery_stagnation, when tool discovery finds nothing new; -
goal_unverified, when the host keeps rejecting the model’s conclusion.
The third idea is that tools declare what they can do, and the runtime enforces it. SideEffectLevel is a closed enum (none, read_only, mutating, external), and tool metadata carries requires_approval, approval_reason and approval_expiry_seconds. The executor only overlaps calls that are safe to overlap.
Code excerpts
The loop’s driver, from core/agent/react_loop.py:
for iteration in range(self._max_iterations):
if self._cancel_requested():
self._mark_cancelled()
break
iteration_result = self._run_iteration(iteration)
if iteration_result.should_stop:
break
if self._hit_cap and not self._cancelled and not self._terminated_by_tool:
...
self._run_safety_handoff()
Stagnation detection is a set of fingerprints, not a counter of identical calls:
fingerprint = _observation_fingerprint(response.tool_calls, results)
if fingerprint in self._seen_observations:
self._stagnant_iterations += 1
else:
self._seen_observations.add(fingerprint)
self._stagnant_iterations = 0
The fingerprint covers the calls and their results, so an observation already seen counts as no progress and a previously unseen one resets the count. A source comment explains that error content is deliberately left out of the fingerprint, so repeated failed calls with identical inputs count as stagnation even if the error text changes.
The safety handoff prompt (abridged), from the same file, tells the model to stop acting and report honestly:
_SAFETY_HANDOFF_PROMPT = """\
The tool loop has stopped for safety ({reason}). Tools are disabled for this response.
...
Do not claim the task completed and do not request or describe another
tool call.
"""
Concurrency is gated by tool metadata, from core/tool/contracts.py:
def _worker_thread_refusal(tool: RegisteredTool) -> str | None:
if tool.role != ToolRole.ACTION:
return f"a {tool.role} tool must run alone"
if tool.requires_approval:
return "a call that needs approval must run alone"
And execute_tool_calls documents the resulting schedule: calls run “in provider order, except that consecutive concurrency-safe calls … run together”, and every other call “runs alone”. Once a result terminates the turn, unstarted calls still get an error result because “providers require one per tool-call id”.
The repo also fences its own agents. AGENTS.md says agents “must never create, edit, rename, move, or delete any SKILL.md”, including the system prompt file, with a narrow exception for verbatim find-and-replace. Skills such as repair-github-ci are therefore human-owned. That skill tells the model to call fix_github_pr_ci(...) and never to run raw gh pr checks, checkout, commit or push itself: “The CI fixer owns PR metadata, failing-check log inspection, fix execution, branch safety, commit, and push.”
Takeaways
- Define the loop against a Protocol, not a concrete agent, so it can be hosted by a CLI, a gateway or an embedded session.
- Give the loop several independent exits (iteration cap, observation stagnation, unverified goal) and a final tools-off handoff.
- Make tool metadata carry side effects and approval, and let the executor derive concurrency from it.
- Keep the dangerous workflow inside one tool that owns branch safety, commit and push, and tell the model not to improvise it with shell commands.
- Enforce layer boundaries in CI so the architecture stays true.
Want an agent pipeline like this built for your team? Get in touch.
Click to load Disqus comments