Skip to content

feat(workflow): support named agent threads - #145

Open
rgarcia wants to merge 2 commits into
QuintinShaw:mainfrom
kernel:hypeship/threaded-agent-sessions
Open

feat(workflow): support named agent threads#145
rgarcia wants to merge 2 commits into
QuintinShaw:mainfrom
kernel:hypeship/threaded-agent-sessions

Conversation

@rgarcia

@rgarcia rgarcia commented Aug 7, 2026

Copy link
Copy Markdown

Problem

I often use workflows where a small-model implementer works in a loop with a large-model reviewer until the reviewer is happy.

Each agent() call currently starts with a fresh conversation history. The implementer has to reconstruct its context every turn, which burns tokens and can make review loops slow or fail to converge.

Change

This adds an optional thread to agent(). Calls using the same thread name re-enter the same Pi session with its full conversation history and session ID:

const change = await agent('Implement the change.', {
  tier: 'small',
  thread: 'work-session',
})

const review = await agent(`Review the implementation:\n${change}`, {
  tier: 'big',
})

await agent(`Address this review:\n${review}`, {
  tier: 'small',
  thread: 'work-session',
})

Threads are scoped to one workflow invocation. Calls on the same thread must be sequential, while unthreaded agents continue to start fresh sessions.

I also considered explicit continuation handles and retaining live AgentSession objects. Named threads keep the existing agent() return value and only retain the underlying session state needed for re-entry.

Testing

  • npm test — 1,194 passed
  • real-provider E2E using openai-codex/gpt-5.6-sol
  • regression coverage for retries, timeouts, concurrent thread use, worktree isolation, persistence, and workflow resume

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