Skip to content

Self Learning

weego edited this page May 28, 2026 · 1 revision

Self-Learning

Self-learning lets an agent write useful learned information into the configured memory backend. It is only meaningful when memory is configured.

Basic Setup

agent = LightAgent(
    name="PolicyAgent",
    instructions="You are a helpful agent.",
    model="gpt-4.1",
    api_key="your_api_key",
    base_url="https://api.openai.com/v1",
    memory=memory_backend,
    self_learning=True,
)

Use a stable user_id:

agent.run("Remember that approvals require the finance manager.", user_id="user_01")
agent.run("What is the approval process?", user_id="user_01")

When to Use It

Use self-learning for:

  • user preferences
  • team-specific procedures
  • repeated operational context
  • internal knowledge captured from conversation

Avoid it for:

  • untrusted public traffic without review
  • high-impact domains without provenance
  • facts that require external verification
  • secrets, credentials, and sensitive personal data

Production Guidance

  • Combine self-learning with MemoryPolicy.
  • Store provenance metadata in the backend.
  • Allow users or administrators to delete or correct learned memories.
  • Review memory writes for high-impact workflows.
  • Separate user memory from tenant-wide knowledge.

See Memory and Security.

Clone this wiki locally