[Feature]: AbstractAgent exposes the active run's identity, not only isRunning
Pre-flight Checklist
- I have searched existing issues and this hasn't been requested yet.
Problem or Motivation
AbstractAgent knows that it is running but not which run it is running. isRunning is a boolean (sdks/typescript/packages/client/src/agent/agent.ts:63), threadId is a public mutable field (:57), and the runId minted in prepareRunAgentInput (:408) exists only inside runAgent and is never kept on the instance. abortRun() (:338) is a bare hook with no access to the identity of the run it is supposed to abort.
Any transport that needs to address a specific run at abort time has to reconstruct that identity itself. CopilotKit's ProxiedCopilotRuntimeAgent does exactly that in CopilotKit/CopilotKit#6982: it captures { threadId, runId } from the RunAgentInput it sends, releases it when the run stream finalizes, and only trusts it while threadId still matches, because the host may reassign threadId under a live run. That bookkeeping duplicates state the base class already computes and every subclass with a cancel endpoint will have to repeat it, with the same thread-switch and late-finalize pitfalls.
Proposed Solution
Expose the active run's identity on AbstractAgent, alongside isRunning:
/** The run this agent is currently executing, or undefined between runs. */
public activeRun?: { threadId: string; runId: string };Set it in runAgent and connectAgent right after prepareRunAgentInput, from the same input the subclass receives, and clear it in the same finalize / finally that resets isRunning. Copy nothing in clone(). The finalize should compare identity before clearing, so a stream that finalizes late cannot release a newer run.
Subclasses can then implement abortRun() as "abort this.activeRun" with no private bookkeeping, and a host that reassigns threadId mid-run can be detected by comparing activeRun.threadId with threadId.
Alternatives Considered
- Keep the bookkeeping in each subclass (current state, see CopilotKit/CopilotKit#6982). Works, but every transport re-derives the same three rules.
- Pass
RunAgentInputtoabortRun(input). Changes a public signature and does not help hosts that callabortRun()from UI code without the input in hand.
Additional Context
CopilotKit/CopilotKit#6982 shows the subclass-side shape that would collapse onto this field.
Source: ag-ui-protocol/ag-ui