Skip to content

Ctx Ace

Ctx ACE — mvp.ctx_ace

Cluster: Context & Retrieval | Type: component | MCP Tools: 26

Overview

Agent Cognition Engine providing a stateful working memory with attention-driven retrieval. Observations are tagged, scored, and stored in memory; the attend operation ranks them by TF-IDF cosine similarity to a query (Jaccard word-overlap fallback when sklearn is unavailable). The forget operation prunes by age or tag, keeping memory lean during long agent runs.

Production caveat: Treat ctx_ace as playbook-based adaptive context, not autonomous model self-training. The MCP tools can persist playbooks and run a Generator → Reflector → Curator loop that proposes and applies localized playbook updates, but they do not fine-tune model weights, prove that future answers improve, or remove the need for evaluation and human review. In launch copy and customer docs, describe this component as "adaptive context/playbook management" rather than a fully self-training system.

When to use:

  • Giving a long-running agent a bounded, queryable working memory
  • Retrieving the most relevant prior observations before generating a response
  • Pruning stale observations to stay within token budget constraints
  • Maintaining a scoped playbook of lessons from evaluated runs, with human-reviewed updates

Example:

from mvp.ctx_ace import CtxACEBlock, ACEInput

block = CtxACEBlock(name="ace")
block.infer(ACEInput(operation="observe", content="The gripper failed on object A", tags=["error"]))
result = block.infer(ACEInput(operation="attend", query="gripper failure", top_k=3))
# result.ok → True; result.value.observations → top-3 most relevant entries

Works well with: context_engine, ctx_recursive, ctx_mnm

Public API

CtxACEBlock(AIBlock[ACEInput, ACEOutput, dict])

Agent Cognition Engine with working memory.

Field Type Default
name str 'ctx_ace'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)

Methods:

infer(data: ACEInput) -> Result[ACEOutput]

Observation(BaseModel)

Field Type Default
content str required
source str ''
relevance_score float 1.0
tags list[str] Field(default_factory=list)
step int 0

ACEInput(BaseModel)

Field Type Default
operation Literal['observe', 'attend', 'recall', 'forget', 'status'] required
content str ''
source str ''
tags list[str] Field(default_factory=list)
relevance_score float 1.0
query str ''
top_k int 5
max_age_steps int \| None None

ACEOutput(BaseModel)

Field Type Default
operation str required
observations list[Observation] Field(default_factory=list)
working_memory_size int 0
summary str ''
degraded bool False
degradation_reason str ''
completion_state str 'complete'
warning_card dict Field(default_factory=dict)
evidence dict Field(default_factory=dict)
request_id str ''
task_id str ''
run_id str ''

CtxACEMCPBlock(AIBlock[MCPACEInput, MCPACEOutput, dict])

26-op ACE context engineering block with SQLite persistence.

Field Type Default
name str 'ctx_ace_mcp'
state dict \| None None
db_path str ':memory:'
resource_bounds ResourceBounds \| None None

Methods:

infer(data: MCPACEInput) -> Result[MCPACEOutput]

MCPACERecord(BaseModel)

Field Type Default
id str ''
record_type str ''
key str ''
value Any None
timestamp str ''
metadata dict Field(default_factory=dict)

MCPACEInput(BaseModel)

Field Type Default
op Literal['playbook_create', 'playbook_add_bullet', 'playbook_get', 'playbook_list', 'playbook_delete', 'generate', 'generate_extract_ids', 'generate_with_context', 'generate_evaluate', 'reflect', 'reflect_no_gt', 'reflect_update_counts', 'reflect_extract_tags', 'curate', 'curate_apply_ops', 'curate_validate_ops', 'curate_stats', 'analyze_bullets', 'parse_bullet', 'find_similar', 'merge_bullets', 'train_step', 'save_session', 'load_session', 'info', 'list_patterns'] required
validation_passed bool False
reviewer_id str ''
name str ''
section str ''
content str ''
playbook_name str ''
question str ''
context str ''
reasoning_trace str ''
predicted_answer str ''
ground_truth str ''
environment_feedback str ''
reflection str ''
playbook_content str ''
bullet_line str ''
threshold float 0.8
bullet_ids list[str] Field(default_factory=list)
response_text str ''
operations_json str ''
session_name str ''
config_json str ''
samples_json str ''
bullet_tags_json str ''
top_k int 5
limit int 50

MCPACEOutput(BaseModel)

Field Type Default
op str ''
key str ''
value Any None
found bool False
count int 0
records list[MCPACERecord] Field(default_factory=list)
retrieved list[Any] Field(default_factory=list)
summary str ''
message str ''
playbook_content str ''
bullet_ids list[str] Field(default_factory=list)
bullet_tags dict Field(default_factory=dict)
operations list[dict] Field(default_factory=list)
accuracy float 0.0
metadata dict Field(default_factory=dict)
degraded bool False
degradation_reason str ''
completion_state str 'complete'
warning_card dict Field(default_factory=dict)
evidence dict Field(default_factory=dict)
request_id str ''
task_id str ''
run_id str ''
available_with str ''

ACEStore

Sync SQLite store with 6 tables.

Constructor:

Parameter Type Default
db_path str ':memory:'

Methods:

create_playbook(name: str, content: str = '') -> str

get_playbook(name: str) -> dict[str, Any] | None

get_playbook_by_id(pid: str) -> dict[str, Any] | None

list_playbooks() -> list[dict[str, Any]]

delete_playbook(name: str) -> bool

update_playbook_content(name: str, content: str) -> bool

increment_bullet_id(name: str) -> int

add_bullet(playbook_id: str, bullet_id: str, section: str, content: str) -> str

get_bullets(playbook_id: str) -> list[dict[str, Any]]

update_bullet_counts(bullet_id: str, helpful_delta: int = 0, harmful_delta: int = 0, playbook_id: str | None = None) -> bool

delete_bullet(bullet_id: str, playbook_id: str | None = None) -> bool

add_reflection(playbook_id: str, question: str, reasoning_trace: str, predicted_answer: str, ground_truth: str, reflection_content: str, bullet_tags_json: str, is_correct: bool) -> str

list_reflections(playbook_id: str, limit: int = 50) -> list[dict[str, Any]]

save_session(name: str, playbook_id: str, config_json: str) -> str

load_session(name: str) -> dict[str, Any] | None

list_sessions() -> list[dict[str, Any]]

update_session(name: str, best_accuracy: float | None = None, total_steps: int | None = None, status: str | None = None) -> bool

add_training_sample(session_id: str, step: int, question: str, context: str, target: str, pre_train_answer: str, post_train_answer: str, pre_train_correct: bool, post_train_correct: bool, reflection_json: str, curator_ops_json: str) -> str

list_training_samples(session_id: str, limit: int = 50) -> list[dict[str, Any]]

set_config(key: str, value_json: str) -> str

get_config(key: str) -> dict[str, Any] | None

count_all() -> dict[str, int]

text_search(query: str, top_k: int = 5) -> list[dict[str, Any]]

MCP Tools

Operation Source
playbook_create ace_mcp
playbook_add_bullet ace_mcp
playbook_get ace_mcp
playbook_list ace_mcp
playbook_delete ace_mcp
generate ace_mcp
generate_extract_ids ace_mcp
generate_with_context ace_mcp
generate_evaluate ace_mcp
reflect ace_mcp
reflect_no_gt ace_mcp
reflect_update_counts ace_mcp
reflect_extract_tags ace_mcp
curate ace_mcp
curate_apply_ops ace_mcp
curate_validate_ops ace_mcp
curate_stats ace_mcp
analyze_bullets ace_mcp
parse_bullet ace_mcp
find_similar ace_mcp
merge_bullets ace_mcp
train_step ace_mcp
save_session ace_mcp
load_session ace_mcp
info ace_mcp
list_patterns ace_mcp