Agent¶
arcana.agents.agent.Agent
¶
Agent(
name,
card,
gateway,
model,
description="",
modifier_cards=None,
memory=None,
soul=None,
system_prompt_override=None,
id=None,
session_manager=None,
extractor=None,
min_confidence_to_store=DEFAULT_MIN_CONFIDENCE_TO_STORE,
min_confidence_for_context=DEFAULT_MIN_CONFIDENCE_FOR_CONTEXT,
summarise_on_close=True,
)
A configured AI agent. Assign a tarot card — get a soul.
Usage
async with ModelGateway(ConnectionStore()) as gw: agent = Agent( name="researcher", card=Card.HERMIT, gateway=gw, model="ollama/hermes-3", ) result = await agent.run("summarize advances in RAG")
Source code in packages/arcana-core/arcana/agents/agent.py
run
async
¶
Run a single prompt. Returns the assistant's response.
Pass session to resume a prior conversation; omit to start a new one.
Source code in packages/arcana-core/arcana/agents/agent.py
stream
async
¶
Stream a response token by token. Records a session with token totals.
Pass session to resume a prior conversation; omit to start a new one.
Source code in packages/arcana-core/arcana/agents/agent.py
arcana.agents.registry.AgentRegistry
¶
Manages agent records (types.Agent) on disk.
Each record lives at ~/.arcana/agents/{id}/agent.json. The registry does not manage runtime agents (agents.Agent) directly — use build_runtime() to reconstruct one from a stored record and an adapter.
Source code in packages/arcana-core/arcana/agents/registry.py
create
¶
create(
name,
card,
model="",
*,
description="",
modifier_cards=None,
system_prompt_override=None,
tags=None,
)
Create a new agent record, resolve card config, and persist to disk.
Source code in packages/arcana-core/arcana/agents/registry.py
get
¶
Return an agent record by ID, or None if not found.
list
¶
Return all non-archived agent records, sorted by name.
Source code in packages/arcana-core/arcana/agents/registry.py
save
¶
Persist an agent record to disk.
Source code in packages/arcana-core/arcana/agents/registry.py
delete
¶
Soft-delete: mark the agent as archived so list() excludes it.
Source code in packages/arcana-core/arcana/agents/registry.py
build_runtime
¶
build_runtime(
record,
gateway,
*,
memory=None,
session_manager=None,
soul=None,
extractor=None,
min_confidence_to_store=DEFAULT_MIN_CONFIDENCE_TO_STORE,
summarise_on_close=True,
)
Reconstruct a runtime Agent from a stored record and gateway.
Source code in packages/arcana-core/arcana/agents/registry.py
build_runtime_with_memory
async
¶
build_runtime_with_memory(
record,
gateway,
*,
home,
enabled=True,
embedding=None,
pools=None,
on_degraded=None,
memory=None,
session_manager=None,
soul=None,
extraction=None,
)
Build a runtime Agent with its memory federation assembled and injected.
Memory is default-on: unless the caller opts out (enabled=False) or
passes an explicit memory override, this assembles a per-agent
federation via build_federation and wires it in. Returns the agent
together with the federation it created (None when memory is off or
overridden) so the caller can close it when the run ends — the agent
stays transport-agnostic and does not own that lifecycle.
The explicit memory override is passed straight through untouched,
which keeps tests and specialised callers able to inject a fake adapter.
extraction selects the memory extraction strategy: the llm strategy
reuses this gateway and the record's model, and falls back to the
deterministic heuristic when no model is configured.
Source code in packages/arcana-core/arcana/agents/registry.py
arcana.agents.session_manager.SessionManager
¶
Manages agent sessions on disk.
Sessions are persisted at ~/.arcana/agents/{agent_id}/sessions/{session_id}.json.
An optional extractor drives :meth:summarise; without one, summaries
fall back to a deterministic, model-free heuristic.
Source code in packages/arcana-core/arcana/agents/session_manager.py
start
¶
Create and return a new running session. Not persisted until close().
Source code in packages/arcana-core/arcana/agents/session_manager.py
append
¶
Add a message to a session and return the new Message.
close
¶
Close the session and persist it to disk (no summarisation).
summarise
async
¶
Distil the session into session.summary, persist, and return it.
Uses extractor (or the manager's own), falling back to a deterministic heuristic when neither is set or the extractor raises. Never propagates an extractor failure — summarisation is best-effort.
Source code in packages/arcana-core/arcana/agents/session_manager.py
close_and_summarise
async
¶
Close the session, optionally summarising and consolidating.
When summarise is set, distils session.summary and — given a
memory adapter — writes one consolidated memory carrying it. The whole
summarise/consolidate step is best-effort: a failure is logged, the
session is still closed and persisted, and the run is never affected.
Source code in packages/arcana-core/arcana/agents/session_manager.py
load
¶
Load a session from disk, or None if not found.
Source code in packages/arcana-core/arcana/agents/session_manager.py
list_sessions
¶
Return all sessions for an agent, sorted by started_at ascending.