Skip to main content

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-ai

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_coreimport 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 demonstration
  • chat.py - Basic multi-peer chat
  • async_example.py - Async/await usage
  • search.py - Context search and retrieval

License

Apache 2.0 - see LICENSE for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

honcho_ai-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

honcho_ai-1.0.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file honcho_ai-1.0.1.tar.gz.

File metadata

  • Download URL: honcho_ai-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.7

File hashes

Hashes for honcho_ai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cd7833fed8d94208c6b0d39e05700baddf85e41a8520a5d9be121e5fecce573d
MD5 b35fc3c73e7a40c73e7c2c33367320be
BLAKE2b-256 2fde6da0b801c16a7cbf478118a0070a1f9073d0632753b0894a2f6baf0296c6

See more details on using hashes here.

File details

Details for the file honcho_ai-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: honcho_ai-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.7

File hashes

Hashes for honcho_ai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c34799a32c90ee4577911901cb49af8463c3b74cf2626bff9586c37947cb887a
MD5 9b5398e7ec583e44317c1c793e35edb5
BLAKE2b-256 b0a5e2f27330682617d38146991d134566720646e3eaf9f5fac5d722792b2b6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page