bind_llm_session_id (providers/session_context.py)

Vibe-Trading · agent/src/providers/session_context.py · python · MIT
ai

Per-conversation LLM session identity. Some relays require a stable per-conversation identifier on every request. OpenCode Go rejects calls that lack ``x-opencode-session`` (HTTP 400 ``MissingSessionID``) because it uses the id for routing and prompt caching. The agent loop binds

# Source: https://github.com/HKUDS/Vibe-Trading | License: MIT | Copyright 2026 Vibe-Trading Contributors
# Provided via justclaw.it.com; keep this notice with the code.
"""Per-conversation LLM session identity.

Some relays require a stable per-conversation identifier on every request.
OpenCode Go rejects calls that lack ``x-opencode-session`` (HTTP 400
``MissingSessionID``) because it uses the id for routing and prompt caching.

The agent loop binds the active Vibe session id here for the duration of a
run; provider adapters read it at request time. A ``ContextVar`` keeps the
binding thread- and task-local, so concurrent sessions never see each other's
id and nothing has to be threaded through every LangChain call site.
"""

from __future__ import annotations

from contextvars import Con

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key