Skip to content

Documentation navigation

Session Config Models

Typed invocation config objects for memory, system tools, orchestration, structured output, and swarm transport.

#Session Config Models

Public configuration models for memory, system tools and model selection.

#Import

Python
from maivn import (
    MemoryConfig,
    MemoryInsightExtractionConfig,
    MemoryGraphExtractionConfig,
    MemoryRetrievalConfig,
    MemorySkillExtractionConfig,
    ModelChoice,
    ModelConfig,
    ModelConfigPart,
    ModelTier,
    PlanningChoice,
    PlanningTier,
    SystemToolsConfig,
)

Agent(...) accepts memory and system-tool config objects or equivalent dictionaries as scope defaults. Swarm(...) takes system-tool defaults only; pass a swarm's memory_config per call. All of them work as invocation overrides. Model selection (ModelConfig) is an invocation argument too. To cap a run's model-loop cycles, use max_cycles on the scope, on RunOptions or on the call. The cap is exact: a run that reaches it raises MaivnSDKError with error_code='max_iterations_exceeded'. See Capping model-loop cycles.

Python
from maivn import Agent, SystemToolsConfig
from maivn.messages import HumanMessage

agent = Agent(
    name="analyst",
    api_key="...",
    system_tools_config=SystemToolsConfig(allowed_tools=["web_search"]),
)

response = agent.invoke(
    [HumanMessage(content="Research this topic")],
    system_tools_config=SystemToolsConfig(allowed_tools=["web_search", "repl"]),
)

#Configuration Layers

LayerWhereMerge behavior
Scope defaultAgent(...), Swarm(...)Applied to every call from that scope
Invocation overrideinvoke(), stream(), ainvoke(), astream()Merged over scope defaults for one call
Compiled toolscompile_tools()Produces current model-visible ToolMetadata schemas

#SystemToolsConfig

Controls which system tools are available to a run.

Plain text
SystemToolsConfig(
    allowed_tools: list[str] | None = None,
    approved_compose_argument_targets: list[str] | None = None,
    allow_private_data: bool | None = None,
    allow_private_data_placeholders: bool | None = None,
)
FieldTypeDefaultDescription
allowed_toolslist[str] | NoneNoneSystem tool allowlist. Use [] to disable all system tools for the call.
approved_compose_argument_targetslist[str] | NoneNonetool.argument strings approved for model-based composition. See compose_argument_policy.
allow_private_databool | NoneNoneAllow system tools to receive raw private_data values. Advanced use only. A scope with allow_private_in_system_tools=True sets it, and a per-call allow_private_in_system_tools wins over both.
allow_private_data_placeholdersbool | NoneNoneAllow system tools to receive private-data placeholders. When unset, the SDK sends nothing and the platform default applies.

Fields you leave as None are not sent. A per-call config overrides only the fields it sets on top of the scope default.

#Model selection

The model argument of invoke() and stream() takes a string, a ModelChoice, or a ModelConfig. Agent(model=...) takes a string and defaults to 'auto'. A string names a tier when it matches one, and an exact model ID otherwise. The Sessions and Streaming guide shows the calls in context.

Python
from maivn import ModelChoice, ModelConfig

config = ModelConfig(
    response=ModelChoice(tier='balanced'),
    thinking='max',
    repl={'model_id': 'provider/model-id'},
    planning='deep',
)
response = agent.invoke('Review this incident report.', model=config)

#Tiers and parts

NameValues
ModelTier'auto', 'fast', 'balanced', 'max', 'ultra'
PlanningTier'auto', 'standard', 'advanced', 'deep'
ModelConfigPart'response', 'thinking', 'compose_argument', 'repl', 'planning'

ModelTier and PlanningTier are separate vocabularies, so a planning part never takes 'fast' or 'balanced'. ModelConfigPart names the parts of a run that ModelConfig can steer.

PartWhat it controls
responseFinal and direct assistant response generation.
thinkingThe think system tool.
compose_argumentModel-based composition of a tool argument.
replREPL code generation and repair.
planningThe planning model.

#ModelChoice and PlanningChoice

Plain text
ModelChoice(tier: ModelTier | None = None, model_id: str | None = None)
PlanningChoice(tier: PlanningTier | None = None, model_id: str | None = None)

Set exactly one of tier and model_id. Setting both, or neither, raises pydantic.ValidationError. A bare string coerces to a choice, and a blank string raises. PlanningChoice.model_id must be non-empty. Both models reject unknown fields.

#ModelConfig

Plain text
ModelConfig(
    response: ModelChoice | None = None,
    thinking: ModelChoice | None = None,
    compose_argument: ModelChoice | None = None,
    repl: ModelChoice | None = None,
    planning: PlanningChoice | None = None,
)

Each part accepts its choice model, a dictionary, or a string. A part you omit keeps platform routing.

MemberPurpose
ModelConfig.for_all(choice=None, *, tier=None, model_id=None, include_planning=False)Applies one choice to response, thinking, compose_argument and repl. Pass exactly one of choice, tier and model_id, or it raises ValueError.
selection_for(part)Returns the configured choice for one ModelConfigPart, or None.
model_ids()Returns the exact model IDs the config references.

for_all leaves planning unset because planning has its own tier vocabulary. include_planning=True applies the choice to planning only when it is an exact model_id. With a tier it raises ValueError.

Python
agent.invoke(
    messages,
    system_tools_config=SystemToolsConfig(
        allowed_tools=["web_search", "repl"],
    ),
)

#MemoryConfig

Controls retrieval and persistence. MemoryConfig and its nested configs refuse fields they do not know, so a removed field raises a validation error. See Upgrading to SDK 3. top_k supplies the default count for each kind of recalled item (skills, insights, resources) when their individual injection counts are omitted. Nested per-call configs replace the corresponding nested scope config. They are not merged field by field.

A team's memory policy sits above this config. The platform lowers persistence_mode to the policy's persistence ceiling and turns memory off when the team's memory switch is off, whatever the config asks for. See Team memory policy.

Plain text
MemoryConfig(
    enabled: bool | None = None,
    level: Literal["none", "glimpse", "focus", "clarity"] | None = None,
    persistence_mode: Literal[
        "persist_none",
        "vector_only",
        "vector_plus_graph",
    ] | None = None,
    retrieval: MemoryRetrievalConfig | None = None,
    skill_extraction: MemorySkillExtractionConfig | None = None,
    insight_extraction: MemoryInsightExtractionConfig | None = None,
    graph_extraction: MemoryGraphExtractionConfig | None = None,
)
FieldTypeDefaultDescription
enabledbool | NoneNonePublic memory master toggle for the invocation.
level"none" | "glimpse" | "focus" | "clarity" | NoneNoneMemory behavior level.
persistence_mode"persist_none" | "vector_only" | "vector_plus_graph" | NoneNoneOptional persistence downscope.
retrievalMemoryRetrievalConfig | NoneNoneRetrieval limits and signal toggles.
skill_extractionMemorySkillExtractionConfig | NoneNoneSkill extraction controls.
insight_extractionMemoryInsightExtractionConfig | NoneNoneInsight extraction controls.
graph_extractionMemoryGraphExtractionConfig | NoneNoneGraph extraction controls.

When you pass a MemoryConfig, the SDK fills the fields you leave unset before it sends the policy: enabled=True, level='clarity', persistence_mode='vector_plus_graph', all three recall toggles on, and three items each for skills, insights and resources unless top_k or an injection count says otherwise. Skill and insight extraction default to on with a max_count of 2. When you pass no MemoryConfig at all, the SDK sends no memory policy and the platform default applies.

Plain text
MemoryRetrievalConfig(
    top_k: int | None = None,
    skills_enabled: bool | None = None,
    insights_enabled: bool | None = None,
    resources_enabled: bool | None = None,
    graph_enabled: bool | None = None,
    graph_injection_max_count: int | None = None,
    skill_injection_max_count: int | None = None,
    insight_injection_max_count: int | None = None,
    resource_injection_max_count: int | None = None,
    insight_relevance_floor: float | None = None,
)
Retrieval fieldTypeValidation
top_kint | None>= 1
skills_enabledbool | NoneOptional skill recall toggle
insights_enabledbool | NoneOptional insight recall toggle
resources_enabledbool | NoneOptional resource recall toggle
graph_enabledbool | NoneOptional graph recall toggle
graph_injection_max_countint | None1 to 16
skill_injection_max_countint | None>= 1
insight_injection_max_countint | None>= 1
resource_injection_max_countint | None>= 1
insight_relevance_floorfloat | None0.0 to 1.0. Similarity floor for recalled memory. See below

insight_relevance_floor is sent as the recall similarity floor, from 0 to 1, and only when you set it. Unset, the platform default of 0.6 applies. The floor applies to all broadly recalled memory: skills, insights and resources that are not bound to the scope. Resources you bind explicitly stay available whatever the floor. This differs slightly from v1, where the value was a relevance score on each insight. It requires a platform release that supports it. Against an older platform, setting it makes the request fail with a validation error, and leaving it unset works everywhere.

Plain text
MemorySkillExtractionConfig(
    enabled: bool | None = None,
    max_count: int | None = None,
)

MemoryInsightExtractionConfig(
    enabled: bool | None = None,
    max_count: int | None = None,
)

MemoryGraphExtractionConfig(enabled=None, max_count=None) controls graph extraction. max_count accepts 1 through 16. Retrieval also accepts graph_enabled and graph_injection_max_count (1 through 16). Graph persistence requires persistence_mode="vector_plus_graph".

Extraction configs have no scope field. For broader reuse, use Portal promotion or client.memory.insights.promote(memory_id, target_scope="project").

#See Also