Skip to content

feat: add --user-prefix for per-agent sticky session routing - #22

Merged
rushilbhat merged 1 commit into
mainfrom
feat/agent-user-prefix
Jul 24, 2026
Merged

feat: add --user-prefix for per-agent sticky session routing#22
rushilbhat merged 1 commit into
mainfrom
feat/agent-user-prefix

Conversation

@rushilbhat

Copy link
Copy Markdown
Contributor

Summary

Adds an optional --user-prefix flag to agent mode. When set, every request body carries an OpenAI user field of "<prefix>-<agent_id>", stable across all turns of an agent's loop.

Why: gateway/router layers that implement session-sticky routing (e.g. keying a routing header off the typed user field) need a per-session identity to pin each agent's growing conversation to one backend worker, so prefix-cache reuse actually happens. Without it, all agents either share one static header identity or have none, and multi-rank deployments round-robin the turns — destroying the cache locality that agent mode exists to measure.

Default behaviour is unchanged (user is omitted unless the flag is passed).

Changes

  • AgentLoopConfig.user_prefix: Option<String> + with_user_prefix builder
  • build_request_body takes the agent_id and stamps user when configured
  • --user-prefix CLI flag wired through agent_cli
  • Tests: absent by default; stamped as "<prefix>-<agent_id>" when set

Testing

cargo test --lib agent — 15 passed (2 new assertions/tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_01GhkeGWXgQY9x9P5c6wzwv5

Copilot AI review requested due to automatic review settings July 24, 2026 14:47
@rushilbhat
rushilbhat merged commit 73acb5d into main Jul 24, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional per-agent sticky-session identity support to batchbench-agent by introducing a --user-prefix flag that stamps each request with a stable OpenAI user field (<prefix>-<agent_id>), enabling router-level session affinity and better prefix-cache locality for agent loops.

Changes:

  • Added AgentLoopConfig.user_prefix: Option<String> plus a with_user_prefix builder.
  • Updated agent request construction to optionally include the OpenAI user field using the agent id.
  • Wired --user-prefix through the agent CLI and added targeted tests for default omission vs. stamping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
rust/src/agent.rs Adds user_prefix to agent loop config and stamps request bodies with user when configured; adds tests.
rust/src/agent_cli.rs Exposes --user-prefix and threads it into AgentLoopConfig.

Comment thread rust/src/agent.rs
Comment on lines +223 to +226
pub fn with_user_prefix(mut self, user_prefix: impl Into<String>) -> Self {
self.user_prefix = Some(user_prefix.into());
self
}
Comment thread rust/src/agent_cli.rs
Comment on lines +383 to +385
if let Some(user_prefix) = &args.user_prefix {
config = config.with_user_prefix(user_prefix.clone());
}
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.

2 participants