Skip to content

feat: add Smolagents memory integration example#544

Open
m1lestones wants to merge 2 commits intoplastic-labs:mainfrom
m1lestones:feat/smolagents-memory-integration
Open

feat: add Smolagents memory integration example#544
m1lestones wants to merge 2 commits intoplastic-labs:mainfrom
m1lestones:feat/smolagents-memory-integration

Conversation

@m1lestones
Copy link
Copy Markdown

@m1lestones m1lestones commented Apr 10, 2026

Summary

  • Adds examples/smolagents/python/ — a full Honcho memory integration for Smolagents (HuggingFace)
  • Demonstrates persistent memory using a ToolCallingAgent with LiteLLMModel, a Tool subclass for memory recall, and Honcho context injected into the task string
  • Follows the same pattern as the existing examples/openai-agents/ example

What's included

examples/smolagents/
├── README.md
└── python/
    ├── main.py
    ├── pyproject.toml
    └── tools/
        ├── client.py
        ├── save_memory.py
        ├── get_context.py
        └── query_memory.py  # QueryMemoryTool(Tool) subclass

How it works

  1. Context injection — Honcho session history is prepended to the agent task string so the model always has recent context.
  2. Tool subclassQueryMemoryTool extends smolagents.Tool, implementing forward() to call Honcho's Dialectic API. The user_id is stored as an instance attribute.
  3. Auto-savechat() persists the user message before the agent runs and the assistant response after.

Test plan

  • Set HONCHO_API_KEY and OPENAI_API_KEY in python/.env
  • pip install "smolagents[litellm]" honcho-ai python-dotenv
  • cd python && python main.py
  • Tell the agent something about yourself, then ask "What do you remember about me?" in a new session

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added comprehensive integration guide explaining Smolagents setup with persistent memory, including required project structure, environment variables, dependencies, and step-by-step usage examples.
  • New Features

    • Added a complete working example demonstrating conversational AI with persistent memory capabilities, enabling automatic conversation history retrieval and natural-language semantic memory recall across separate user sessions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

Warning

Rate limit exceeded

@m1lestones has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 58 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 58 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d3d9adc-067d-405e-a49b-e78c46f72771

📥 Commits

Reviewing files that changed from the base of the PR and between 31717c0 and 7a33df3.

📒 Files selected for processing (3)
  • examples/smolagents/python/main.py
  • examples/smolagents/python/tools/query_memory.py
  • examples/smolagents/python/tools/save_memory.py

Walkthrough

This PR adds a complete Smolagents integration example with Honcho persistent memory, including documentation, project configuration, a conversational agent entrypoint, and modular tools for Honcho client setup, context retrieval, memory querying via Dialectic API, and memory persistence.

Changes

Cohort / File(s) Summary
Documentation
examples/smolagents/README.md
Introduces the integration pattern, expected project structure, required environment variables, installation steps, quick-start usage example with chat() function, control flow explanation, and concept mapping.
Project Configuration
examples/smolagents/python/pyproject.toml
Defines Python package metadata, minimum Python 3.10+ requirement, and dependencies for smolagents[litellm], honcho-ai, and python-dotenv.
Honcho Integration Tools
examples/smolagents/python/tools/client.py, examples/smolagents/python/tools/get_context.py, examples/smolagents/python/tools/query_memory.py, examples/smolagents/python/tools/save_memory.py
Implements modular tools: HonchoContext dataclass and get_client() for setup, get_context() for fetching session conversation history, QueryMemoryTool Smolagents tool exposing Dialectic API queries, and save_memory() for persisting messages.
Agent Entrypoint
examples/smolagents/python/main.py
Implements chat(user_id, message, session_id) function orchestrating the agent flow: fetching recent context, injecting history, creating a ToolCallingAgent with QueryMemoryTool, running inference via gpt-4-mini, and persisting both user and assistant messages to Honcho.

Sequence Diagram

sequenceDiagram
    participant User
    participant Chat as chat()
    participant Honcho as Honcho Client
    participant Agent as ToolCallingAgent
    participant OpenAI as OpenAI API
    participant Dialectic as Dialectic API

    User->>Chat: (user_id, message, session_id)
    Chat->>Honcho: get_context(ctx, tokens=2000)
    Honcho-->>Chat: context_history
    Chat->>Agent: forward(context + message)
    Agent->>OpenAI: LLM call
    OpenAI-->>Agent: response
    alt Agent calls QueryMemoryTool
        Agent->>Honcho: peer.chat(query)
        Honcho->>Dialectic: semantic search
        Dialectic-->>Honcho: results
        Honcho-->>Agent: retrieved memory
    end
    Agent-->>Chat: assistant_response
    Chat->>Honcho: save_memory(user_message, "user")
    Chat->>Honcho: save_memory(assistant_response, "assistant")
    Chat-->>User: assistant_response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ajspig
  • VVoruganti

Poem

🐰 A bunny hops through memory halls,
Smolagents whisper through Honcho's calls,
Context flows, tools remember all,
Dialectic dances at semantic's call,
Fluffy persistence, never to fall!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: adding a complete Smolagents memory integration example with documentation and functional code.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants