Skip to content

thirdeye agent command - #23

Merged
duncankmckinnon merged 10 commits into
mainfrom
agent-command
Jun 28, 2026
Merged

thirdeye agent command#23
duncankmckinnon merged 10 commits into
mainfrom
agent-command

Conversation

@duncankmckinnon

Copy link
Copy Markdown
Owner

Context

thirdeye (PyPI: thrdi) is a Python CLI that hooks into agentic coding tools (Claude Code,
Codex, Gemini CLI, Cursor) and records their events into a per-session event store at
~/.thirdeye/traces/<platform>/<session_id>/.

This plan adds a new thirdeye agent "<task>" command — a one-shot agent harness that
injects thirdeye's shipped skills as context, then invokes a coding agent (Claude Code by
default) to work through the task. The primary use case is session introspection: reviewing
today's sessions, auditing token usage, or identifying inefficiencies. With --fix, the
agent's tool access is broadened to allow file edits so it can apply recommendations.

The command reuses the existing eval/agents/ adapter infrastructure (AgentAdapter,
ClaudeAdapter, CodexAdapter, GeminiAdapter, get_adapter()) without modifying it.
All new code lives in a new src/thirdeye/agent/ package.

After the agent run completes, any new sessions the agent spawned on its platform are
automatically tagged thirdeye-agent (using TagStore.add(0, "thirdeye-agent", source="auto")).
This lets users filter agent-initiated sessions with thirdeye list --tag thirdeye-agent and
exclude them from general session analysis. Tagging is best-effort — failures are swallowed
so they never block the command.

The four deliverables, spread across three waves:

src/thirdeye/agent/
  __init__.py       # empty package marker
  prompt.py         # skill loading + prompt composition
  harness.py        # wraps AgentAdapter with mode-specific arg overrides
  exec.py           # streaming subprocess execution
src/thirdeye/commands/agent.py   # click CLI command
src/thirdeye/cli.py              # one-line addition to wire in the command

Key existing modules to understand

src/thirdeye/eval/agents/base.pyAgentAdapter ABC, AgentConfig dataclass,
ConfigAdapter concrete implementation. AgentAdapter.build_command(prompt, cwd) returns
[command, *resolved_args] with {prompt} substituted.

src/thirdeye/eval/agents/__init__.pyget_adapter(name, thirdeye_home) returns
an adapter instance; list_agent_names(thirdeye_home) returns sorted list of available
names (builtins + user YAML overrides).

src/thirdeye/eval/agents/claude.pyClaudeAdapter uses
claude -p {prompt} --output-format json --allowedTools "Bash(thirdeye *) ...". The
harness overrides these args for agent mode (text output, mode-appropriate tools).

src/thirdeye/web/agentic.py — reference for the importlib.resources pattern for
loading shipped skills and stripping YAML frontmatter. Study _read_skill_body() and
_FRONTMATTER_RE.

src/thirdeye/config.pyConfig.load() reads THIRDEYE_HOME env var or defaults
to ~/.thirdeye.

Shipped skills (all under src/thirdeye/skills/<name>/SKILL.md):

  • use-thirdeye — how to use the thirdeye CLI to retrieve and inspect sessions
  • thirdeye-review — five-step workflow for auditing agent sessions for inefficiencies
  • thirdeye-evals — how to run and interpret session evaluations
  • thirdeye-filter — NL-to-filter skill (used by the web UI; not typically needed here)

Tasks

  • Prompt builder
  • Agent harness
  • Streaming exec
  • Agent command

🤖 Reviewed by workbench. Report: .workbench/agent-command/wrap-up/agent-command/review.md

duncankmckinnon and others added 10 commits June 26, 2026 16:48
Wraps any AgentAdapter and overrides CLI args for review or fix mode,
switching eval adapters from JSON output/restricted tools to text output
with mode-appropriate tool access. Unknown adapters fall back to their
own config.args unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Creates src/thirdeye/agent/__init__.py (package marker) and
src/thirdeye/agent/prompt.py with build_agent_prompt() that loads
shipped skills via importlib.resources, strips YAML frontmatter,
and assembles a structured prompt with context block and task.
Adds tests/test_agent_prompt.py covering all specified cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The join applies to all parts including context and task, so "---"
always appears between context and TASK even when no skills are loaded.
Replace the incorrect `not in` check with `count == 1`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements run_agent_streaming in src/thirdeye/agent/exec.py: drives
subprocess with Popen for real-time stdout streaming, drains stderr on a
background thread to avoid deadlock, and tags any new sessions spawned
during the run with 'thirdeye-agent' (best-effort, failures swallowed).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…adjust exit code propagation on success, and add integration/unit tests for session tagging and cwd option
@duncankmckinnon
duncankmckinnon merged commit 16ac955 into main Jun 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant