Prospection Loop¶
A MemAgent answers when it is asked. With prospection on (proactive
mode; it replaces the proactive agents of 0.17.29), a background pass also
reads what the agent remembers, the tools it has and the workflows it has
saved, works out what is likely to happen next, and writes down what to do
about it as a prospect. Every prospect cites the memories it came from, and
prospects are stored apart from everything else, in MemoryType.PROSPECTS, so
a guess is never recalled as something that happened.
Prospection is off by default (prospection=False). Coming from proactive
agents? See Upgrading from proactive agents.
Quick start¶
from memorizz import MemAgent, MemAgentBuilder, OpenAI
agent = (
MemAgentBuilder()
.with_name("Ada")
.with_model(OpenAI(model="gpt-4o-mini"))
.with_prospection(True) # or MemAgent(..., prospection=True)
.build()
)
agent.run("I fly to Tokyo on Wednesday and still need three hotel options.")
# A pass starts in the background after each turn. Ask for one directly: it
# waits for a pass already running, then runs its own.
prospects = agent.prospect(force=True)
for p in prospects:
print(p.title, p.risk_label, p.score, p.source_memory_ids)
agent.accept_prospect(prospects[0].prospect_id) # the agent carries it out
In a real run of this pattern (gpt-4o-mini, a trip-planning agent told "I fly
to Lisbon on 14 March for a conference. No hotel yet."), the pass proposed
Research hotel options for Lisbon conference, citing the two conversation
turns it came from, and accepting it ran it.
Architecture¶
The loop runs in five stages outside the main thread:
- Trigger & Admission: checks policy, snooze, daily token budget (with adaptive multiplier), cooldown, and change fingerprint before calling a model.
- Seed Selection (
SeedSelector): ranks candidate memory seeds across open commitments, deadlines, recent tool/workflow failures (TOOL_LOG,WORKFLOW_MEMORY), important facts (ENTITY_MEMORY,KNOWLEDGE_BASE), connected read-only sources, explicit activity, and (whenpredict=True) recurring patterns. - Recombination: runs a bounded pass on
agent.background_model(falling back toagent.model) across episodic, semantic, and procedural memory plus the agent's liveCapabilityCatalog(tools, parameters, deterministic risk tiers, saved workflows, active skills). - Score, Deduplicate & Write: computes deterministic
risk_tierandscore = confidence * value * urgency - cost, drops results belowmin_score, deduplicates/refreshes live matches, and writes toMemoryType.PROSPECTS. Every prospect must cite at least one verifiedsource_memory_id("no sources, no write"). - Gate (Main-Thread Pull & Reversibility): at turn boundaries (
run()andrun_stream()), the main thread pulls top-k(default3) valid prospects abovemin_scoreafter lazy source invalidation and injects them ephemerally as[PROSPECTION — UNVERIFIED PREDICTIONS]without persisting them into conversation history.
First-class MemoryType.PROSPECTS¶
Prospects are stored in MemoryType.PROSPECTS across all four providers
(FileSystem, MongoDB, Oracle, Notion):
- Recall isolation:
MemoryType.PROSPECTSis excluded from ordinary episodic and semantic recall so a simulation is never retrieved as something that actually happened. - Mandatory provenance:
ProspectStore.put_prospect()rejects any prospect withoutsource_memory_ids. - Expiry & trace retention: expired prospects transition to
status="expired", are never surfaced again, and stay persisted for outcome metrics. - Lazy source invalidation: before surfacing a prospect to the main thread,
cited source memories are checked; if deleted or modified since creation, the
prospect is marked
status="stale".
Tool factoring & deterministic risk tiers¶
The recombiner inspects every live tool on agent.tool_manager (name,
description, parameter schema) alongside saved WORKFLOW_MEMORY and active
SKILLBOX entries. Hallucinated tool or workflow names are rejected.
Risk tiers are always computed deterministically from @governed_tool
declarations and MCP tool annotations — never self-assigned by the LLM:
| Tier | Action type | Policy |
|---|---|---|
| Tier 0 | Read-only prep or internal memory domain |
Background loop may auto-run at level="medium" / "high" (auto_run_max_risk_tier >= 0) under CAREFUL guard |
| Tier 1 | Reversible internal write / undeclared callable | Auto-runs only at level="high" (auto_run_max_risk_tier >= 1); pauses for approval under CAREFUL |
| Tier 2 | Outbound, destructive, requires_approval=True, or externally tainted without allow_external_actions=True |
Always requires user confirmation (auto_run_max_risk_tier never accepts 2) |
Tick modes & adaptive token budget¶
| Mode | Fires when | Fits |
|---|---|---|
"event" (default) |
The end of each turn, an important memory write, and compaction; session_end when you call agent.note_prospection_event("session_end") |
Most agents — compute scales with activity |
"clock" |
Every clock_interval_minutes via start_prospection(), prospection_tick(), or memorizz prospection run |
Time-bound calendars and monitoring |
"async" |
Continuous change-watching worker — computes seed fingerprint cheaply and only calls a model when inputs changed | Fast-changing environments |
Every mode is capped by token_budget_per_day (default 50_000). With
adaptive_budget=True, recording "useful" outcomes raises the effective
budget multiplier (up to 2.0x), while "not_useful", "rejected", or
"expired" unused prospects lower it (down to 0.25x).
Shadow mode & outcome feedback¶
Evaluate prospection safely before surfacing anything to users with
shadow=True:
agent = MemAgent(
model=OpenAI(model="gpt-4o-mini"),
prospection={"level": "low", "shadow": True},
)
Answer each prospect once: accept it, defer it, or dismiss it. Then record whether an accepted one helped, which tunes the seed weights and the adaptive budget over time:
first, second, third = agent.prospect(force=True)[:3]
agent.accept_prospect(first.prospect_id) # carries it out
agent.record_prospect_outcome(first.prospect_id, "useful")
agent.defer_prospect(second.prospect_id, hours=24) # ask again tomorrow
agent.dismiss_prospect(third.prospect_id) # not wanted
print(agent.prospection_metrics())
A prospect made in shadow mode is kept for metrics only, so it can't be accepted or deferred.
Headless worker & Playground UI¶
memorizz prospection run # saved agents with prospection enabled
memorizz prospection run --once # run due ticks once, then exit
memorizz prospection run --agent AGENT_ID
In memorizz ui, open any agent's Playground to adjust the Prospection level,
tick mode (event/clock/async), shadow mode, source scanning, and habit
prediction, inspect risk-tier badges and source citations, approve or reject
tool calls inline, and mark executed prospects Useful or Not useful.
Upgrading from proactive agents (0.17.29 and 0.17.30)¶
Proactive agents became the prospection loop in 0.17.31. Code written for them
keeps working through aliases: MemAgent(proactive=...), with_proactive(),
suggest(), suggestions(), accept_suggestion(), dismiss_suggestion(),
snooze_suggestions(), on_suggestion(), proactive_status(),
proactive_tick(), start_proactive(), stop_proactive(), the
memorizz.proactive module, memorizz proactive run and the
/api/agents/{id}/proactive routes. An agent saved with proactive loads with
the same level of prospection. What changed:
- Statuses:
offeredis nowproposed,doneisexecuted,dismissedisrejectedandsnoozedisdeferred; accepting without running givesaccepted. Filter by the new names:suggestions(status="offered")finds nothing. - Old suggestions are not carried over. They were kept in one shared-memory
record per agent; prospects live in
MemoryType.PROSPECTS. Suggestions offered before the upgrade no longer appear (they are still deleted with the agent). - A pass runs after every turn for an agent with prospection on (the
default
tick_mode="event"), and up to three prospects go into each turn's prompt. Proactive agents ran only when asked. For the old behaviour usetick_mode="clock"andsurface_to_main_thread=False. - Levels act less on their own:
mediumruns only Tier 0 (read-only) steps,highTier 0 and Tier 1. A step that names a tool needing approval is Tier 2 and is only proposed, wherehighused to start it and pause at that tool. - Events and records: stream events are
prospect.<status>with aprospectkey (weresuggestion.<status>),describe_memory()reportsprospection, and aProspectreplacesSuggestion(idandpromptare still readable).