Skip to main content
The runtime-resolution subsystem maps agent and model references to concrete runtime instances at turn-time, enabling dynamic model switching and custom routing logic.
Handoffs no longer use this subsystem. As of PR #2178, handoffs always delegate directly to agent.chat() / agent.achat(). The runtime-resolution layer is used by other parts of the SDK for agent-level runtime configuration. If you came here for handoff execution behaviour, see Agent Handoffs.
The user changes model or runtime references on an agent; the resolver picks the concrete runtime on the next turn.

Quick Start

1

Simple Usage

Update the target model at any time — the next invocation reads the live llm value.
2

With Configuration

Clear the runtime cache after credential rotation or register a custom resolver:

How It Works

The subsystem reads the agent’s current llm (or model) attribute at invocation time, not at construction time.
Handoffs always execute via agent.chat() / agent.achat() directly — they do not call into this subsystem. Runtime resolution is used for agent-level model configuration and caching, not for handoff execution.

Configuration Options

SessionContext

Passed to resolve_runtime to scope caching and track depth.

Cache constants

Cache keys use the format "{session_id}:{agent_id}:{model_ref}" — caches are session-isolated so different conversations never share runtimes.

Common Patterns

Mid-conversation model swap

Force cache refresh

Introspect resolved runtimes


Best Practices

Model re-resolution happens at each invocation boundary. Changing agent.llm is effective immediately for the next call — no restart needed.
The 5-minute TTL means old runtimes may linger after you rotate API keys. Call clear_runtime_cache() to evict all entries and force fresh connections.
Return False from supports_model for models you do not handle. The built-in DefaultRuntimeResolver acts as the final fallback, so returning False simply delegates back to it.
If you need to change how a handoff target executes, configure the target agent itself (instructions, tools, llm). The target agent’s full chat() pipeline runs on every handoff — this subsystem is not in that path.

Public API

All names are importable from praisonaiagents.runtime:

resolve_runtime

The main entry point. Checks the TTL cache first; creates and caches a new runtime if none exists or the entry expired.

RuntimeProtocol / AgentRuntimeProtocol

Protocols that custom runtimes must satisfy. Only relevant when building a custom resolver.

Runtime Selection

Choose which runtime executes each model

Agent Handoffs

Agent-to-agent delegation — handoffs always use agent.chat()