Official DX Optimized Python SDK for Honcho
Project description
Honcho Python SDK
The official Python library for the Honcho conversational memory platform. Honcho provides tools for managing peers, sessions, and conversation context across multi-party interactions, enabling advanced conversational AI applications with persistent memory and theory-of-mind capabilities.
Installation
pip install honcho-sdk
Quick Start
from honcho import Honcho
# Initialize client
client = Honcho(api_key="your-api-key")
# Create peers (participants in conversations)
alice = client.peer("alice")
bob = client.peer("bob")
# Create a session for group conversations
session = client.session("conversation-1")
# Add messages to the session
session.add_messages([
alice.message("Hello, Bob!"),
bob.message("Hi Alice, how are you?")
])
# Query conversation context
response = alice.chat("What did Bob say to me?")
print(response)
Core Concepts
Peers
Peers represent participants in conversations.
# Create peers
assistant = client.peer("assistant")
user = client.peer("user-123")
# Chat with global context
response = user.chat("What did I talk about yesterday?")
# Chat with perspective of another peer
response = user.chat("Does the assistant know my preferences?", target=assistant)
Sessions
Sessions group related conversations and messages:
# Create a session
session = client.session("project-discussion")
# Add peers to session
session.add_peers([alice, bob])
# Add messages
session.add_messages([
alice.message("Let's discuss the project timeline"),
bob.message("I think we need two more weeks")
])
# Get conversation context
context = session.get_context()
Messages and Context
Retrieve and use conversation history:
# Get messages from a session
messages = session.get_messages()
# Convert to OpenAI format for further prompting
openai_messages = context.to_openai(assistant="assistant")
# Convert to Anthropic format for further prompting
anthropic_messages = context.to_anthropic(assistant="assistant")
Async Support
from honcho import AsyncHoncho
async def main():
client = AsyncHoncho(api_key="your-api-key")
peer = client.peer("user")
response = await peer.chat("Hello!")
print(response)
Metadata Management
# Set peer metadata
user.set_metadata({"location": "San Francisco", "preferences": {"theme": "dark"}})
# Query using metadata context
response = user.chat("What's the weather like where I am?")
# Session metadata
session.set_metadata({"topic": "project-planning", "priority": "high"})
Multi-Perspective Queries
# Alice's view of what Bob knows
response = alice.chat("Does Bob remember our discussion about the budget?", target=bob)
# Session-specific perspective
response = alice.chat("What does Bob think about this project?",
target=bob,
session_id=session.id)
Configuration
Environment Variables
export HONCHO_API_KEY="your-api-key"
export HONCHO_URL="https://api.honcho.dev" # Optional
export HONCHO_WORKSPACE_ID="your-workspace" # Optional
Client Options
client = Honcho(
api_key="your-api-key",
environment="production", # or "local", "demo"
workspace_id="custom-workspace",
base_url="https://api.honcho.dev"
)
Examples
Check out the examples/
directory for complete usage examples:
example.py
- Comprehensive feature demonstrationchat.py
- Basic multi-peer chatasync_example.py
- Async/await usagesearch.py
- Context search and retrieval
License
Apache 2.0 - see LICENSE for details.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file honcho_ai-1.0.0.tar.gz
.
File metadata
- Download URL: honcho_ai-1.0.0.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
42725498be66a630fa1ef034091c407971744956a53a8b773e333653bdff99b6
|
|
MD5 |
de7d3fc90020d4925b75278cc1a3d2d5
|
|
BLAKE2b-256 |
2668e91f4ddabe17fec4358ae0bb7350b0a4752c22b93dd6e0d609b17717fb5c
|
File details
Details for the file honcho_ai-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: honcho_ai-1.0.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
af69703c0576cf36a69bb0d71d87fc288616d13d7201e62449a5235ea3120c33
|
|
MD5 |
cb548cae46602f64a78a5bf207807a8a
|
|
BLAKE2b-256 |
a876b4d508d0e7cc1d35bb7ac27305771d15e02a8b62c1d47f6f9ea710ce2af6
|