Skip to content

perf: ArgentSessionManager + 113-tool registry rebuilt every turn — cache across turns #406

Description

@webdevtodayjason

Summary

Every agent turn rebuilds the entire session pipeline from scratch:

[argent-runtime] Using ArgentSessionManager for session
[argent-runtime] Using ArgentSettingsManager
[argent-runtime] Using createArgentAgentSession (tools=113)

Combined with the 113-tool registry construction, this accounts for ~5.5 seconds of pre-I/O wall-clock per turn (gateway tony-stark phase async_io_started=5509ms). Within a single ongoing conversation, none of this should change between turns — the same session, same settings, same tools.

Repro

Run two consecutive turns in the Argent TUI. Tail ~/.argent/logs/gateway.log for the [tony-stark] phase lines. Observe that async_io_started, tools_created, pre_session, session_created all hover around 5.5s on both turns even though the conversation, settings, and tool list have not changed.

Proposed fix

Cache the session-pipeline state keyed by (sessionId, agentId, settingsRevision, toolRegistryHash):

  • First turn of a session: build everything as today (~5.5s).
  • Subsequent turns: reuse the cached session manager, settings manager, agent session, and tool registry. Expected pre-I/O time: <100ms.
  • Cache invalidation: bump on settings change, tool registry change (e.g. operator enables a new toolkit), or explicit session reset.

Acceptance criteria

  • tony-stark telemetry shows async_io_started < 200ms on the 2nd+ turn of a session under no-change conditions.
  • First turn is unchanged or improved (cache miss is fine).
  • Cache invalidates correctly when settings, tools, or sessionId change. Add unit tests for each invalidation path.
  • No regression: changing the model profile mid-conversation does the right thing.

Related

🤖 Filed from a live perf investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions