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
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.
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
#SystemToolsConfig
Controls which system tools are available to a run.
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,
)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.
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
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.
#ModelChoice and PlanningChoice
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
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.
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.
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.
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,
)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.
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,
)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.
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
- Agent - Agent constructor and invocation arguments
- Swarm - Swarm constructor and invocation arguments
- System Tools Guide - System tool allowlists and approvals
- Memory and Recall Guide - Memory behavior and assets