Skip to content

← Back to YouLab

Background agents run scheduled or manual tasks to enrich agent memory using Honcho dialectic queries.

Background agents enable theory-of-mind (ToM) integration by:

  1. Querying Honcho for insights about students
  2. Enriching agent memory with those insights
  3. Writing audit trails to archival memory
┌──────────────────────────────────────────────────────────────┐
│ Background Agent Flow │
│ │
│ Trigger (cron/manual) │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ BackgroundAgentRunner│ │
│ └──────────┬──────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ HonchoClient │──────│ Honcho Service │ │
│ │ query_dialectic() │ │ (ToM insights) │ │
│ └──────────┬──────────┘ └─────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ MemoryEnricher │ │
│ │ (audit trail) │ │
│ └──────────┬──────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Letta Agent │ │
│ │ (memory blocks) │ │
│ └─────────────────────┘ │
└──────────────────────────────────────────────────────────────┘

Background agents are configured via TOML files in config/courses/.

Location: config/courses/{course-name}.toml

id = "college-essay"
name = "College Essay Coaching"
[[background_agents]]
id = "insight-harvester"
name = "Student Insight Harvester"
enabled = true
agent_types = ["tutor"]
user_filter = "all"
batch_size = 50
[background_agents.triggers]
schedule = "0 3 * * *" # Cron expression
manual = true
[background_agents.triggers.idle]
enabled = false
threshold_minutes = 30
cooldown_minutes = 60
[[background_agents.queries]]
id = "learning_style"
question = "What learning style works best for this student?"
session_scope = "all"
target_block = "human"
target_field = "context_notes"
merge_strategy = "append"
FieldTypeDescription
idstringUnique course identifier
namestringDisplay name
background_agentsarrayList of background agents
FieldTypeDefaultDescription
idstringRequiredUnique agent identifier
namestringRequiredDisplay name
enabledbooltrueWhether agent runs
agent_typesarray["tutor"]Which agent types to process
user_filterstring"all"User filtering
batch_sizeint50Users per batch
triggersTriggers-Trigger configuration
queriesarray[]Dialectic queries
FieldTypeDefaultDescription
schedulestringnullCron expression
idle.enabledboolfalseEnable idle trigger
idle.threshold_minutesint30Idle time threshold
idle.cooldown_minutesint60Cooldown between runs
manualbooltrueAllow manual triggers
FieldTypeDefaultDescription
idstringRequiredQuery identifier
questionstringRequiredNatural language question
session_scopeenum"all"all, recent, current, specific
recent_limitint5Sessions for recent scope
target_blockstringRequired"human" or "persona"
target_fieldstringRequiredField to update
merge_strategyenum"append"append, replace, llm_diff

Location: src/youlab_server/background/runner.py

Executes background agents based on configuration.

from youlab_server.background.runner import BackgroundAgentRunner
runner = BackgroundAgentRunner(
letta_client=letta,
honcho_client=honcho,
)
result = await runner.run_agent(
config=agent_config,
user_ids=["user123"], # Optional: specific users
)
print(f"Processed {result.users_processed} users")
print(f"Applied {result.enrichments_applied} enrichments")
FieldTypeDescription
agent_idstringBackground agent ID
started_atdatetimeStart time
completed_atdatetimeEnd time
users_processedintUsers processed
queries_executedintQueries run
enrichments_appliedintSuccessful enrichments
errorslistError messages

Location: src/youlab_server/memory/enricher.py

Handles external memory updates with audit trailing.

from youlab_server.memory.enricher import MemoryEnricher, MergeStrategy
enricher = MemoryEnricher(letta_client)
result = enricher.enrich(
agent_id="agent-abc123",
block="human",
field="context_notes",
content="Student prefers visual explanations",
strategy=MergeStrategy.APPEND,
source="background:insight-harvester",
source_query="What learning style works best?",
)

Each enrichment writes an audit entry to the agent’s archival memory:

[MEMORY_EDIT 2025-01-08T03:00:00]
Source: background:insight-harvester
Block: human
Field: context_notes
Strategy: append
Query: What learning style works best?
Content: Student prefers visual explanations...

List configured background agents.

Terminal window
curl http://localhost:8100/background/agents

Manually trigger a background agent.

Terminal window
curl -X POST http://localhost:8100/background/insight-harvester/run \
-H "Content-Type: application/json" \
-d '{"user_ids": ["user123"]}'

Hot-reload TOML configuration.

Terminal window
curl -X POST http://localhost:8100/background/config/reload

See httpService#Background Endpoints for full API details.


StrategyBehavior
appendAdd to existing list (default, safe)
replaceOverwrite existing content
llm_diffIntelligently merge (TODO: LLM integration)

The college-essay.toml config includes an insight harvester that:

  1. Runs daily at 3 AM
  2. Queries all students with tutor agents
  3. Asks three questions per student:
    • Learning style preferences
    • Engagement patterns
    • Communication style
  4. Enriches memory blocks with insights
[[background_agents.queries]]
id = "learning_style"
question = "What learning style works best for this student? Do they prefer examples, theory, or hands-on practice?"
session_scope = "all"
target_block = "human"
target_field = "context_notes"
merge_strategy = "append"