chore: (docs) Reconcile new SDK conventions in docs (#355)

This commit is contained in:
Vineeth Voruganti 2026-01-28 10:58:40 -05:00 committed by GitHub
parent 4add711711
commit 4fcf6c4574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 208 additions and 207 deletions

View File

@ -15,11 +15,11 @@ Assuming reasoning is enabled, you can control the perspectives representations
When `observe_me=true` (the default), Honcho forms one representation per peer, reasoning over every message written to that peer across all sessions.
You can retrieve a subset of conclusions from a peer's representation using `get_representation()`:
You can retrieve a subset of conclusions from a peer's representation using `representation()`:
```python
# Retrieve conclusions from Honcho's representation of Alice (across all sessions)
alice_rep = session.get_representation("alice")
alice_rep = session.representation("alice")
# Or via chat
response = alice.chat("What are Alice's main interests?", session_id=session.id)
@ -93,7 +93,7 @@ charlie = honcho.peer("charlie")
session.add_peers([alice, bob, charlie])
# Enable Alice to form representations of others
session.set_peer_config(alice, SessionPeerConfig(observe_others=True))
session.set_peer_configuration(alice, SessionPeerConfig(observe_others=True))
# Add messages
session.add_messages([
@ -111,9 +111,9 @@ session2.add_messages([
])
# Retrieve conclusions from different perspectives
honcho_view = session.get_representation("alice") # Across all sessions
bob_view = session.get_representation("alice", target="bob") # Alice's view of Bob
charlie_view = session2.get_representation("alice", target="charlie") # Alice's view of Charlie
honcho_view = session.representation("alice") # Across all sessions
bob_view = session.representation("alice", target="bob") # Alice's view of Bob
charlie_view = session2.representation("alice", target="charlie") # Alice's view of Charlie
```
```typescript TypeScript
@ -128,7 +128,7 @@ const charlie = await honcho.peer("charlie");
await session.addPeers([alice, bob, charlie]);
await session.setPeerConfig(alice, { observeOthers: true });
await session.setPeerConfiguration(alice, { observeOthers: true });
await session.addMessages([
bob.message("I had pancakes for breakfast."),
@ -144,9 +144,9 @@ await session2.addMessages([
]);
// Retrieve conclusions from different perspectives
const honchoView = await session.getRepresentation("alice"); // Across all sessions
const bobView = await session.getRepresentation("alice", { target: "bob" }); // Alice's view of Bob
const charlieView = await session2.getRepresentation("alice", { target: "charlie" }); // Alice's view of Charlie
const honchoView = await session.representation("alice"); // Across all sessions
const bobView = await session.representation("alice", { target: "bob" }); // Alice's view of Bob
const charlieView = await session2.representation("alice", { target: "charlie" }); // Alice's view of Charlie
```
</CodeGroup>
@ -224,7 +224,7 @@ This architecture enables:
## Semantic Search Parameters
Both `get_representation()` and `chat()` support semantic filtering to retrieve a subset of relevant conclusions. You can optionally filter by session to retrieve only conclusions from specific session context:
Both `representation()` and `chat()` support semantic filtering to retrieve a subset of relevant conclusions. You can optionally filter by session to retrieve only conclusions from specific session context:
| Parameter | Type | Description |
|-----------|------|-------------|
@ -237,7 +237,7 @@ Both `get_representation()` and `chat()` support semantic filtering to retrieve
<CodeGroup>
```python Python
# Retrieve conclusions about billing from Alice's representation of Bob
alice_view_billing = session.get_representation(
alice_view_billing = session.representation(
"alice",
target="bob",
search_query="billing issues",
@ -247,7 +247,7 @@ alice_view_billing = session.get_representation(
```
```typescript TypeScript
const aliceViewBilling = await session.getRepresentation("alice", {
const aliceViewBilling = await session.representation("alice", {
target: "bob",
searchQuery: "billing issues",
searchTopK: 10,
@ -267,5 +267,5 @@ Directional representations update automatically through the reasoning pipeline
The pipeline respects scoping—Honcho's representations reason over messages across all sessions, while directional representations only reason over messages from sessions where the observer was an active participant.
<Note>
Conclusions are cached for fast retrieval. Use `get_representation()` to retrieve stored conclusions for dashboards and analytics. Use `peer.chat()` when you need query-specific reasoning with natural language.
Conclusions are cached for fast retrieval. Use `representation()` to retrieve stored conclusions for dashboards and analytics. Use `peer.chat()` when you need query-specific reasoning with natural language.
</Note>

View File

@ -22,15 +22,15 @@ from honcho import Honcho
honcho = Honcho()
# Simple peer filter
peers = honcho.get_peers(filters={"peer_id": "alice"})
peers = honcho.peers(filters={"peer_id": "alice"})
# Simple session filter with metadata
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {"type": "support"}
})
# Simple message filter
messages = honcho.get_messages(filters={
messages = honcho.messages(filters={
"session_id": "support-chat-1",
"peer_id": "alice"
})
@ -44,19 +44,19 @@ import { Honcho } from "@honcho-ai/sdk";
const honcho = new Honcho({});
// Simple peer filter
const peers = await honcho.getPeers({
const peers = await honcho.peers({
filters: { peer_id: "alice" }
});
// Simple session filter with metadata
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
metadata: { type: "support" }
}
});
// Simple message filter
const messages = await honcho.getMessages({
const messages = await honcho.messages({
filters: {
session_id: "support-chat-1",
peer_id: "alice"
@ -76,7 +76,7 @@ Use AND to require all conditions to be true:
<CodeGroup>
```python Python
messages = honcho.get_messages(filters={
messages = honcho.messages(filters={
"AND": [
{"session_id": "chat-1"},
{"created_at": {"gte": "2024-01-01"}}
@ -86,7 +86,7 @@ messages = honcho.get_messages(filters={
```typescript TypeScript
(async () => {
const messages = await honcho.getMessages({
const messages = await honcho.messages({
filters: {
AND: [
{ session_id: "chat-1" },
@ -105,7 +105,7 @@ Use OR to match any of the specified conditions:
<CodeGroup>
```python Python
# Find messages from either alice or bob
messages = session.get_messages(filters={
messages = session.messages(filters={
"OR": [
{"peer_id": "alice"},
{"peer_id": "bob"}
@ -113,7 +113,7 @@ messages = session.get_messages(filters={
})
# Complex OR with metadata conditions
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"OR": [
{"metadata": {"priority": "high"}},
{"metadata": {"urgent": True}},
@ -125,7 +125,7 @@ sessions = honcho.get_sessions(filters={
```typescript TypeScript
(async () => {
// Find messages from either alice or bob
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
OR: [
{ peer_id: "alice" },
@ -135,7 +135,7 @@ sessions = honcho.get_sessions(filters={
});
// Complex OR with metadata conditions
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
OR: [
{ metadata: { priority: "high" } },
@ -155,14 +155,14 @@ Use NOT to exclude specific conditions:
<CodeGroup>
```python Python
# Find all peers except alice
peers = honcho.get_peers(filters={
peers = honcho.peers(filters={
"NOT": [
{"peer_id": "alice"}
]
})
# Find sessions that are NOT completed
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"NOT": [
{"metadata": {"status": "completed"}}
]
@ -172,7 +172,7 @@ sessions = honcho.get_sessions(filters={
```typescript TypeScript
(async () => {
// Find all peers except alice
const peers = await honcho.getPeers({
const peers = await honcho.peers({
filters: {
NOT: [
{ peer_id: "alice" }
@ -181,7 +181,7 @@ sessions = honcho.get_sessions(filters={
});
// Find sessions that are NOT completed
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
NOT: [
{ metadata: { status: "completed" } }
@ -199,7 +199,7 @@ Create sophisticated queries by combining different logical operators:
<CodeGroup>
```python Python
# Find messages from alice OR bob, but NOT where message has archived set to true in metadata
messages = session.get_messages(filters={
messages = session.messages(filters={
"AND": [
{
"OR": [
@ -219,7 +219,7 @@ messages = session.get_messages(filters={
```typescript TypeScript
(async () => {
// Find messages from alice OR bob, but NOT where message has archived set to true in metadata
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
AND: [
{
@ -249,12 +249,12 @@ Use comparison operators for range queries and advanced matching:
<CodeGroup>
```python Python
# Find sessions created after a specific date
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"created_at": {"gte": "2024-01-01"}
})
# Find messages within a date range
messages = session.get_messages(filters={
messages = session.messages(filters={
"created_at": {
"gte": "2024-01-01",
"lte": "2024-12-31"
@ -262,7 +262,7 @@ messages = session.get_messages(filters={
})
# Metadata numeric comparisons
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {
"score": {"gt": 8.5},
"duration": {"lte": 3600}
@ -273,14 +273,14 @@ sessions = honcho.get_sessions(filters={
```typescript TypeScript
(async () => {
// Find sessions created after a specific date
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
created_at: { gte: "2024-01-01" }
}
});
// Find messages within a date range
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
created_at: {
gte: "2024-01-01",
@ -290,7 +290,7 @@ sessions = honcho.get_sessions(filters={
});
// Metadata numeric comparisons
const filteredSessions = await honcho.getSessions({
const filteredSessions = await honcho.sessions({
filters: {
metadata: {
score: { gt: 8.5 },
@ -307,19 +307,19 @@ sessions = honcho.get_sessions(filters={
<CodeGroup>
```python Python
# Find messages from specific peers in a session
messages = session.get_messages(filters={
messages = session.messages(filters={
"peer_id": {"in": ["alice", "bob", "charlie"]}
})
# Find sessions with specific tags
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {
"tag": {"in": ["important", "urgent", "follow-up"]}
}
})
# Not equal comparisons
peers = honcho.get_peers(filters={
peers = honcho.peers(filters={
"metadata": {
"status": {"ne": "inactive"}
}
@ -329,14 +329,14 @@ peers = honcho.get_peers(filters={
```typescript TypeScript
(async () => {
// Find messages from specific peers in a session
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
peer_id: { in: ["alice", "bob", "charlie"] }
}
});
// Find sessions with specific tags
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
metadata: {
tag: { in: ["important", "urgent", "follow-up"] }
@ -345,7 +345,7 @@ peers = honcho.get_peers(filters={
});
// Not equal comparisons
const peers = await honcho.getPeers({
const peers = await honcho.peers({
filters: {
metadata: {
status: { ne: "inactive" }
@ -365,7 +365,7 @@ Metadata filtering is particularly powerful in Honcho, supporting nested conditi
<CodeGroup>
```python Python
# Simple metadata equality
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {
"type": "customer_support",
"priority": "high"
@ -373,7 +373,7 @@ sessions = honcho.get_sessions(filters={
})
# Nested metadata objects
peers = honcho.get_peers(filters={
peers = honcho.peers(filters={
"metadata": {
"profile": {
"role": "admin",
@ -386,7 +386,7 @@ peers = honcho.get_peers(filters={
```typescript TypeScript
(async () => {
// Simple metadata equality
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
metadata: {
type: "customer_support",
@ -396,7 +396,7 @@ peers = honcho.get_peers(filters={
});
// Nested metadata objects
const peers = await honcho.getPeers({
const peers = await honcho.peers({
filters: {
metadata: {
profile: {
@ -419,7 +419,7 @@ If you want to do advanced queries like these, make sure not to create metadata
<CodeGroup>
```python Python
# Metadata with comparison operators
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {
"score": {"gte": 4.0, "lte": 5.0},
"created_by": {"ne": "system"},
@ -428,7 +428,7 @@ sessions = honcho.get_sessions(filters={
})
# Complex metadata conditions
messages = session.get_messages(filters={
messages = session.messages(filters={
"AND": [
{"metadata": {"sentiment": {"in": ["positive", "neutral"]}}},
{"metadata": {"confidence": {"gt": 0.8}}},
@ -440,7 +440,7 @@ messages = session.get_messages(filters={
```typescript TypeScript
(async () => {
// Metadata with comparison operators
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
metadata: {
score: { gte: 4.0, lte: 5.0 },
@ -451,7 +451,7 @@ messages = session.get_messages(filters={
});
// Complex metadata conditions
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
AND: [
{ metadata: { sentiment: { in: ["positive", "neutral"] } } },
@ -471,17 +471,17 @@ Use wildcards (*) to match any value for a field:
<CodeGroup>
```python Python
# Find all sessions with any peer_id (essentially all sessions)
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"peer_id": "*"
})
# Wildcard in lists - matches everything
messages = session.get_messages(filters={
messages = session.messages(filters={
"peer_id": {"in": ["alice", "bob", "*"]}
})
# Metadata wildcards
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"metadata": {
"type": "*", # Any type
"status": "active" # But status must be active
@ -492,21 +492,21 @@ sessions = honcho.get_sessions(filters={
```typescript TypeScript
(async () => {
// Find all sessions with any peer_id (essentially all sessions)
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
peer_id: "*"
}
});
// Wildcard in lists - matches everything
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
peer_id: { in: ["alice", "bob", "*"] }
}
});
// Metadata wildcards
const filteredSessions = await honcho.getSessions({
const filteredSessions = await honcho.sessions({
filters: {
metadata: {
type: "*", // Any type
@ -525,12 +525,12 @@ sessions = honcho.get_sessions(filters={
<CodeGroup>
```python Python
# Find workspaces by name pattern
workspaces = honcho.get_workspaces(filters={
workspaces = honcho.workspaces(filters={
"name": {"contains": "prod"}
})
# Filter by metadata
workspaces = honcho.get_workspaces(filters={
workspaces = honcho.workspaces(filters={
"metadata": {
"environment": "production",
"team": {"in": ["backend", "frontend", "devops"]}
@ -541,14 +541,14 @@ workspaces = honcho.get_workspaces(filters={
```typescript TypeScript
(async () => {
// Find workspaces by name pattern
const workspaces = await honcho.getWorkspaces({
const workspaces = await honcho.workspaces({
filters: {
name: { contains: "prod" }
}
});
// Filter by metadata
const workspaces = await honcho.getWorkspaces({
const workspaces = await honcho.workspaces({
filters: {
metadata: {
environment: "production",
@ -568,7 +568,7 @@ workspaces = honcho.get_workspaces(filters={
from datetime import datetime, timedelta
week_ago = (datetime.now() - timedelta(days=7)).isoformat()
messages = session.get_messages(filters={
messages = session.messages(filters={
"AND": [
{"content": {"icontains": "error"}},
{"created_at": {"gte": week_ago}},
@ -577,7 +577,7 @@ messages = session.get_messages(filters={
})
# Find messages in specific sessions with sentiment analysis
messages = session.get_messages(filters={
messages = session.messages(filters={
"AND": [
{"session_id": {"in": ["support-1", "support-2", "support-3"]}},
{"metadata": {"sentiment": "negative"}},
@ -590,7 +590,7 @@ messages = session.get_messages(filters={
(async () => {
// Find error messages from the last week
const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
AND: [
{ content: { icontains: "error" } },
@ -601,7 +601,7 @@ messages = session.get_messages(filters={
});
// Find messages in specific sessions with sentiment analysis
const sentimentMessages = await session.getMessages({
const sentimentMessages = await session.messages({
filters: {
AND: [
{ session_id: { in: ["support-1", "support-2", "support-3"] } },
@ -624,7 +624,7 @@ from honcho.exceptions import FilterError
try:
# Invalid filter - unsupported operator
messages = session.get_messages(filters={
messages = session.messages(filters={
"created_at": {"invalid_operator": "2024-01-01"}
})
except FilterError as e:
@ -633,7 +633,7 @@ except FilterError as e:
try:
# Invalid column name
sessions = honcho.get_sessions(filters={
sessions = honcho.sessions(filters={
"nonexistent_field": "value"
})
except FilterError as e:
@ -644,7 +644,7 @@ except FilterError as e:
(async () => {
try {
// Invalid filter - unsupported operator
const messages = await session.getMessages({
const messages = await session.messages({
filters: {
created_at: { invalid_operator: "2024-01-01" }
}
@ -658,7 +658,7 @@ except FilterError as e:
try {
// Invalid column name
const sessions = await honcho.getSessions({
const sessions = await honcho.sessions({
filters: {
nonexistent_field: "value"
}

View File

@ -1,10 +1,10 @@
---
title: 'Get Context'
description: 'Learn how to use get_context() to retrieve and format conversation context for LLM integration'
description: 'Learn how to use context() to retrieve and format conversation context for LLM integration'
icon: 'messages'
---
The `get_context()` method is a powerful feature that retrieves formatted conversation context from sessions, making it easy to integrate with LLMs like OpenAI, Anthropic, and others. This guide covers everything you need to know about working with session context.
The `context()` method is a powerful feature that retrieves formatted conversation context from sessions, making it easy to integrate with LLMs like OpenAI, Anthropic, and others. This guide covers everything you need to know about working with session context.
<Note>
By default, the context includes a blend of summary and messages ***which covers the entire session history of a peer***.
@ -14,7 +14,7 @@ Summaries are automatically generated at intervals and recent messages are inclu
## Basic Usage
The `get_context()` method is available on all Session objects and returns a `SessionContext` that contains the formatted conversation history.
The `context()` method is available on all Session objects and returns a `SessionContext` that contains the formatted conversation history.
<CodeGroup>
```python Python
@ -25,7 +25,7 @@ honcho = Honcho()
session = honcho.session("conversation-1")
# Get basic context (not very useful before adding any messages!)
context = session.get_context()
context = session.context()
```
```typescript TypeScript
@ -37,14 +37,14 @@ import { Honcho } from "@honcho-ai/sdk";
const session = await honcho.session("conversation-1");
// Get basic context (not very useful before adding any messages!)
const context = await session.getContext();
const context = await session.context();
})();
```
</CodeGroup>
## Context Parameters
The `get_context()` method accepts several optional parameters to customize the retrieved context:
The `context()` method accepts several optional parameters to customize the retrieved context:
### Token Limits
@ -53,19 +53,19 @@ Control the size of the context by setting a maximum token count:
<CodeGroup>
```python Python
# Limit context to 1500 tokens
context = session.get_context(tokens=1500)
context = session.context(tokens=1500)
# Limit context to 3000 tokens for larger conversations
context = session.get_context(tokens=3000)
context = session.context(tokens=3000)
```
```typescript TypeScript
(async () => {
// Limit context to 1500 tokens
const context = await session.getContext({ tokens: 1500 });
const context = await session.context({ tokens: 1500 });
// Limit context to 3000 tokens for larger conversations
const context = await session.getContext({ tokens: 3000 });
const context = await session.context({ tokens: 3000 });
})();
```
</CodeGroup>
@ -77,19 +77,19 @@ Enable summary mode (on by default) to get a condensed version of the conversati
<CodeGroup>
```python Python
# Get context with summary enabled -- will contain both summary and messages
context = session.get_context(summary=True)
context = session.context(summary=True)
# Combine summary=False with token limits to get more messages
context = session.get_context(summary=False, tokens=2000)
context = session.context(summary=False, tokens=2000)
```
```typescript TypeScript
(async () => {
// Get context with summary enabled -- will contain both summary and messages
const context = await session.getContext({ summary: true });
const context = await session.context({ summary: true });
// Combine summary=False with token limits to get more messages
const context = await session.getContext({
const context = await session.context({
summary: false,
tokens: 2000
});
@ -104,7 +104,7 @@ You can include a peer's [representation](/v3/documentation/core-concepts/repres
<CodeGroup>
```python Python
# Get context with peer representation included
context = session.get_context(
context = session.context(
tokens=2000,
peer_target="user-123" # Include representation of user-123
)
@ -114,7 +114,7 @@ print(context.peer_representation) # String representation
print(context.peer_card) # List of peer card items
# Get representation from a specific peer's perspective
context = session.get_context(
context = session.context(
tokens=2000,
peer_target="user-123",
peer_perspective="assistant" # From assistant's viewpoint
@ -124,7 +124,7 @@ context = session.get_context(
```typescript TypeScript
(async () => {
// Get context with peer representation included
const context = await session.getContext({
const context = await session.context({
tokens: 2000,
peerTarget: "user-123" // Include representation of user-123
});
@ -134,7 +134,7 @@ context = session.get_context(
console.log(context.peerCard); // Array of peer card items
// Get representation from a specific peer's perspective
const perspectiveContext = await session.getContext({
const perspectiveContext = await session.context({
tokens: 2000,
peerTarget: "user-123",
peerPerspective: "assistant" // From assistant's viewpoint
@ -149,7 +149,7 @@ Use `search_query` to fetch semantically relevant conclusions based on a query s
<CodeGroup>
```python Python
context = session.get_context(
context = session.context(
tokens=2000,
peer_target="user-123",
search_query="What are my coding preferences?",
@ -162,7 +162,7 @@ context = session.get_context(
```typescript TypeScript
(async () => {
const context = await session.getContext({
const context = await session.context({
tokens: 2000,
peerTarget: "user-123",
searchQuery: "What are my coding preferences?",
@ -184,7 +184,7 @@ Use `limit_to_session` to only include conclusions from the current session:
<CodeGroup>
```python Python
# Get context limited to this session's conclusions only
context = session.get_context(
context = session.context(
tokens=2000,
peer_target="user-123",
limit_to_session=True # Only conclusions from this session
@ -194,7 +194,7 @@ context = session.get_context(
```typescript TypeScript
(async () => {
// Get context limited to this session's conclusions only
const context = await session.getContext({
const context = await session.context({
tokens: 2000,
peerTarget: "user-123",
limitToSession: true // Only conclusions from this session
@ -239,7 +239,7 @@ session.add_messages([
])
# Get context and convert to OpenAI format
context = session.get_context()
context = session.context()
openai_messages = context.to_openai(assistant=assistant)
# The messages are now ready for OpenAI API
@ -263,7 +263,7 @@ print(openai_messages)
]);
// Get context and convert to OpenAI format
const context = await session.getContext();
const context = await session.context();
const openaiMessages = context.toOpenAI(assistant);
// The messages are now ready for OpenAI API
@ -283,7 +283,7 @@ Convert context to Anthropic's Claude format:
<CodeGroup>
```python Python
# Get context and convert to Anthropic format
context = session.get_context()
context = session.context()
anthropic_messages = context.to_anthropic(assistant=assistant)
# Ready for Anthropic API
@ -293,7 +293,7 @@ print(anthropic_messages)
```typescript TypeScript
(async () => {
// Get context and convert to Anthropic format
const context = await session.getContext();
const context = await session.context();
const anthropicMessages = context.toAnthropic(assistant);
// Ready for Anthropic API
@ -328,7 +328,7 @@ session.add_messages([
])
# Get context for LLM
messages = session.get_context(tokens=2000).to_openai(assistant=assistant)
messages = session.context(tokens=2000).to_openai(assistant=assistant)
# Add new user message and get AI response
messages.append({
@ -370,7 +370,7 @@ import { Honcho } from "@honcho-ai/sdk";
]);
// Get context for LLM
const messages = (await session.getContext({ tokens: 2000 })).toOpenAI(assistant);
const messages = (await session.context({ tokens: 2000 })).toOpenAI(assistant);
// Add new user message and get AI response
const response = await openai.chat.completions.create({
@ -395,7 +395,7 @@ import { Honcho } from "@honcho-ai/sdk";
<CodeGroup>
```python Python
def chat_loop():
"""Example of a continuous chat loop using get_context()"""
"""Example of a continuous chat loop using context()"""
session = honcho.session("chat-session")
user = honcho.peer("user")
@ -411,7 +411,7 @@ def chat_loop():
session.add_messages([user.message(user_input)])
# Get conversation context
context = session.get_context(tokens=2000)
context = session.context(tokens=2000)
messages = context.to_openai(assistant=assistant)
# Get AI response
@ -451,7 +451,7 @@ chat_loop()
await session.addMessages([user.message(userInput)]);
// Get conversation context
const context = await session.getContext({ tokens: 2000 });
const context = await session.context({ tokens: 2000 });
const messages = context.toOpenAI(assistant);
// Get AI response
@ -486,7 +486,7 @@ For very long conversations, use summaries to maintain context while controlling
long_session = honcho.session("long-conversation")
# Get summarized context to fit within token limits
context = long_session.get_context(summary=True, tokens=1500)
context = long_session.context(summary=True, tokens=1500)
messages = context.to_openai(assistant=assistant)
# This will include a summary of older messages and recent full messages
@ -499,7 +499,7 @@ print(f"Context contains {len(messages)} formatted messages")
const longSession = await honcho.session("long-conversation");
// Get summarized context to fit within token limits
const context = await longSession.getContext({
const context = await longSession.context({
summary: true,
tokens: 1500
});
@ -523,9 +523,9 @@ analyzer = honcho.peer("data-analyzer")
moderator = honcho.peer("moderator")
# Get context formatted for each assistant type
chatbot_context = session.get_context().to_openai(assistant=chatbot)
analyzer_context = session.get_context().to_openai(assistant=analyzer)
moderator_context = session.get_context().to_openai(assistant=moderator)
chatbot_context = session.context().to_openai(assistant=chatbot)
analyzer_context = session.context().to_openai(assistant=analyzer)
moderator_context = session.context().to_openai(assistant=moderator)
# Each context will format the conversation from that assistant's perspective
```
@ -538,7 +538,7 @@ moderator_context = session.get_context().to_openai(assistant=moderator)
const moderator = await honcho.peer("moderator");
// Get context formatted for each assistant type
const context = await session.getContext();
const context = await session.context();
const chatbotContext = context.toOpenAI(chatbot);
const analyzerContext = context.toOpenAI(analyzer);
const moderatorContext = context.toOpenAI(moderator);
@ -557,21 +557,21 @@ Always set appropriate token limits to control costs and ensure context fits wit
<CodeGroup>
```python Python
# Good: Set reasonable token limits based on your model
context = session.get_context(tokens=3000) # For GPT-4
context = session.get_context(tokens=1500) # For smaller models
context = session.context(tokens=3000) # For GPT-4
context = session.context(tokens=1500) # For smaller models
# Good: Use summaries for very long conversations
context = session.get_context(summary=True, tokens=2000)
context = session.context(summary=True, tokens=2000)
```
```typescript TypeScript
(async () => {
// Good: Set reasonable token limits based on your model
const context = await session.getContext({ tokens: 3000 }); // For GPT-4
const context = await session.getContext({ tokens: 1500 }); // For smaller models
const context = await session.context({ tokens: 3000 }); // For GPT-4
const context = await session.context({ tokens: 1500 }); // For smaller models
// Good: Use summaries for very long conversations
const context = await session.getContext({ summary: true, tokens: 2000 });
const context = await session.context({ summary: true, tokens: 2000 });
})();
```
</CodeGroup>
@ -583,7 +583,7 @@ For applications with frequent context retrieval, consider caching context when
<CodeGroup>
```python Python
# Cache context for multiple LLM calls within the same request
context = session.get_context(tokens=2000)
context = session.context(tokens=2000)
openai_messages = context.to_openai(assistant=assistant)
anthropic_messages = context.to_anthropic(assistant=assistant)
@ -593,7 +593,7 @@ anthropic_messages = context.to_anthropic(assistant=assistant)
```typescript TypeScript
(async () => {
// Cache context for multiple LLM calls within the same request
const context = await session.getContext({ tokens: 2000 });
const context = await session.context({ tokens: 2000 });
const openaiMessages = context.toOpenAI(assistant);
const anthropicMessages = context.toAnthropic(assistant);
@ -609,7 +609,7 @@ Always handle potential errors when retrieving context:
<CodeGroup>
```python Python
try:
context = session.get_context(tokens=2000)
context = session.context(tokens=2000)
except Exception as e:
print(f"Error getting context: {e}")
# Handle error appropriately (fallback to basic context, retry, etc.)
@ -618,7 +618,7 @@ except Exception as e:
```typescript TypeScript
(async () => {
try {
const context = await session.getContext({ tokens: 2000 });
const context = await session.context({ tokens: 2000 });
} catch (error) {
console.error(`Error getting context: ${error}`);
// Handle error appropriately (fallback to basic context, retry, etc.)
@ -629,7 +629,7 @@ except Exception as e:
## Conclusion
The `get_context()` method is essential for integrating Honcho sessions with LLMs. By understanding how to:
The `context()` method is essential for integrating Honcho sessions with LLMs. By understanding how to:
- Retrieve context with appropriate parameters
- Convert context to LLM-specific formats

View File

@ -62,7 +62,7 @@ session.add_messages([
response = alice.chat("What did the assistant tell this user about the weather?")
# Get conversation context for LLM completions
context = session.get_context()
context = session.context()
openai_messages = context.to_openai(assistant=assistant)
```
@ -89,7 +89,7 @@ await session.addMessages([
const response = await alice.chat("What did the assistant tell this user about the weather?");
// Get conversation context for LLM completions
const context = await session.getContext();
const context = await session.context();
const openaiMessages = context.toOpenAI(assistant);
```
</CodeGroup>
@ -192,10 +192,10 @@ peer = honcho.peer(id)
session = honcho.session(id)
# List all peers in workspace
peers = honcho.get_peers()
peers = honcho.peers()
# List all sessions in workspace
sessions = honcho.get_sessions()
sessions = honcho.sessions()
# Search across all content in workspace
results = honcho.search(query)
@ -205,7 +205,7 @@ metadata = honcho.get_metadata()
honcho.set_metadata(dict)
# Get list of all workspace IDs
workspaces = honcho.get_workspaces()
workspaces = honcho.workspaces()
```
```typescript TypeScript
@ -216,10 +216,10 @@ const peer = await honcho.peer(id);
const session = await honcho.session(id);
// List all peers in workspace (returns Page<Peer>)
const peers = await honcho.getPeers();
const peers = await honcho.peers();
// List all sessions in workspace (returns Page<Session>)
const sessions = await honcho.getSessions();
const sessions = await honcho.sessions();
// Search across all content in workspace (returns Page<any>)
const results = await honcho.search(query);
@ -229,7 +229,7 @@ const metadata = await honcho.getMetadata();
await honcho.setMetadata(metadata);
// Get list of all workspace IDs
const workspaces = await honcho.getWorkspaces();
const workspaces = await honcho.workspaces();
```
</CodeGroup>
@ -269,7 +269,7 @@ session.add_messages([
])
# Get peer's sessions
sessions = alice.get_sessions()
sessions = alice.sessions()
# Search peer's messages
results = alice.search("programming")
@ -280,11 +280,11 @@ metadata["location"] = "Paris"
alice.set_metadata(metadata)
# Get peer context (representation + peer card in one call)
context = alice.get_context()
context = alice.get_context(target="bob") # What alice knows about bob
context = alice.context()
context = alice.context(target="bob") # What alice knows about bob
# Get working representation with semantic search
rep = alice.get_representation(search_query="preferences", search_top_k=10)
rep = alice.representation(search_query="preferences", search_top_k=10)
# Access conclusions
self_conclusions = alice.conclusions.list() # Self-conclusions
@ -318,7 +318,7 @@ await session.addMessages([
]);
// Get peer's sessions
const sessions = await alice.getSessions();
const sessions = await alice.sessions();
// Search peer's messages
const results = await alice.search("programming");
@ -331,11 +331,11 @@ await alice.setMetadata({
});
// Get peer context (representation + peer card in one call)
const context = await alice.getContext();
const targetContext = await alice.getContext("bob"); // What alice knows about bob
const context = await alice.context();
const targetContext = await alice.context({ target: "bob" }); // What alice knows about bob
// Get working representation with semantic search
const rep = await alice.getRepresentation(undefined, undefined, {
const rep = await alice.representation({
searchQuery: "preferences",
searchTopK: 10
});
@ -348,20 +348,20 @@ const bobConclusions = await alice.conclusionsOf("bob").list(); // Conclusions
### Peer Context
The `get_context()` method on peers retrieves both the working representation and peer card in a single API call:
The `context()` method on peers retrieves both the working representation and peer card in a single API call:
<CodeGroup>
```python Python
# Get peer's own context
context = alice.get_context()
context = alice.context()
print(context.representation) # Working representation
print(context.peer_card) # Peer card as list of strings
# Get context about another peer (what alice knows about bob)
bob_context = alice.get_context(target="bob")
bob_context = alice.context(target="bob")
# Get context with semantic search
context = alice.get_context(
context = alice.context(
target="bob",
search_query="work preferences",
search_top_k=10,
@ -373,15 +373,16 @@ context = alice.get_context(
```typescript TypeScript
// Get peer's own context
const context = await alice.getContext();
const context = await alice.context();
console.log(context.representation); // Working representation
console.log(context.peerCard); // Peer card as array of strings
// Get context about another peer (what alice knows about bob)
const bobContext = await alice.getContext("bob");
const bobContext = await alice.context({ target: "bob" });
// Get context with semantic search
const searchedContext = await alice.getContext("bob", {
const searchedContext = await alice.context({
target: "bob",
searchQuery: "work preferences",
searchTopK: 10,
searchMaxDistance: 0.8,
@ -512,9 +513,9 @@ session.set_peers([alice, bob, charlie]) # Replace all peers
session.remove_peers([alice])
# Get session peers and their configurations
peers = session.get_peers()
peer_config = session.get_peer_config(alice)
session.set_peer_config(alice, SessionPeerConfig(observe_me=False))
peers = session.peers()
peer_config = session.get_peer_configuration(alice)
session.set_peer_configuration(alice, SessionPeerConfig(observe_me=False))
# Message management
session.add_messages([
@ -523,13 +524,13 @@ session.add_messages([
])
# Get messages
messages = session.get_messages()
messages = session.messages()
# Get conversation context
context = session.get_context(summary=True, tokens=2000)
context = session.context(summary=True, tokens=2000)
# Get context with peer representation included
context = session.get_context(
context = session.context(
tokens=2000,
peer_target="user",
peer_perspective="assistant",
@ -545,9 +546,9 @@ context = session.get_context(
results = session.search("help")
# Working representation queries with semantic search
global_rep = session.get_representation("alice")
targeted_rep = session.get_representation(alice, target=bob)
searched_rep = session.get_representation(
global_rep = session.representation("alice")
targeted_rep = session.representation(alice, target=bob)
searched_rep = session.representation(
"alice",
search_query="preferences",
search_top_k=10,
@ -593,7 +594,7 @@ await session.removePeers([alice]);
await session.removePeers("single-peer-id");
// Get session peers
const peers = await session.getPeers();
const peers = await session.peers();
// Message management
await session.addMessages([
@ -602,13 +603,13 @@ await session.addMessages([
]);
// Get messages
const messages = await session.getMessages();
const messages = await session.messages();
// Get conversation context
const context = await session.getContext({ summary: true, tokens: 2000 });
const context = await session.context({ summary: true, tokens: 2000 });
// Get context with peer representation included
const richContext = await session.getContext({
const richContext = await session.context({
tokens: 2000,
peerTarget: "user",
peerPerspective: "assistant",
@ -616,7 +617,7 @@ const richContext = await session.getContext({
limitToSession: true,
searchTopK: 10,
searchMaxDistance: 0.8,
includeMostDerived: true,
includeMostFrequent: true,
maxConclusions: 25
});
@ -624,12 +625,12 @@ const richContext = await session.getContext({
const results = await session.search("help");
// Working representation queries with semantic search
const globalRep = await session.getRepresentation("alice");
const targetedRep = await session.getRepresentation(alice, { target: bob });
const searchedRep = await session.getRepresentation("alice", undefined, {
const globalRep = await session.representation("alice");
const targetedRep = await session.representation(alice, { target: bob });
const searchedRep = await session.representation("alice", {
searchQuery: "preferences",
searchTopK: 10,
includeMostDerived: true
includeMostFrequent: true
});
// Upload a file to create messages
@ -699,7 +700,7 @@ Provides formatted conversation context for LLM integration:
<CodeGroup>
```python Python
# Get session context
context = session.get_context(summary=True, tokens=1500)
context = session.context(summary=True, tokens=1500)
# Convert to LLM-friendly formats
openai_messages = context.to_openai(assistant=assistant)
@ -708,7 +709,7 @@ anthropic_messages = context.to_anthropic(assistant=assistant)
```typescript TypeScript
// Get session context
const context = await session.getContext({ summary: true, tokens: 1500 });
const context = await session.context({ summary: true, tokens: 1500 });
// Convert to LLM-friendly formats
const openaiMessages = context.toOpenAI(assistant);
@ -818,7 +819,7 @@ const moderatorView = await moderator.chat("What feedback am I getting?", {
import openai
# Get conversation context
context = session.get_context(tokens=3000)
context = session.context(tokens=3000)
messages = context.to_openai(assistant=assistant)
# Call OpenAI API
@ -836,7 +837,7 @@ import OpenAI from 'openai';
const openai = new OpenAI();
// Get conversation context
const context = await session.getContext({ tokens: 3000 });
const context = await session.context({ tokens: 3000 });
const messages = context.toOpenAI(assistant);
// Call OpenAI API
@ -896,8 +897,8 @@ session.add_messages([
])
# Filter messages by metadata
finance_messages = session.get_messages(filters={"metadata": {"topic": "finance"}})
action_items = session.get_messages(filters={"metadata": {"action_item": True}})
finance_messages = session.messages(filters={"metadata": {"topic": "finance"}})
action_items = session.messages(filters={"metadata": {"action_item": True}})
```
```typescript TypeScript
@ -918,10 +919,10 @@ await session.addMessages([
]);
// Filter messages by metadata
const financeMessages = await session.getMessages({
const financeMessages = await session.messages({
filters: { metadata: { topic: "finance" } }
});
const actionItems = await session.getMessages({
const actionItems = await session.messages({
filters: { metadata: { action_item: true } }
});
```
@ -932,17 +933,17 @@ const actionItems = await session.getMessages({
<CodeGroup>
```python Python
# Iterate through all sessions
for session in honcho.get_sessions():
for session in honcho.sessions():
print(f"Session: {session.id}")
# Iterate through session messages
for message in session.get_messages():
for message in session.messages():
print(f" {message.peer_id}: {message.content}")
```
```typescript TypeScript
// Get paginated results
const peersPage = await honcho.getPeers();
const peersPage = await honcho.peers();
// Iterate through all items
for await (const peer of peersPage) {
@ -996,7 +997,7 @@ peers = [honcho.peer(f"user-{i}") for i in range(100)] # Fast
session.add_messages([peer.message(f"Message {i}") for i, peer in enumerate(peers)])
# Use context limits to control token usage
context = session.get_context(tokens=1500) # Limit context size
context = session.context(tokens=1500) # Limit context size
```
```typescript TypeScript
@ -1011,10 +1012,10 @@ await session.addMessages(
);
// Use context limits to control token usage
const context = await session.getContext({ tokens: 1500 }); // Limit context size
const context = await session.context({ tokens: 1500 }); // Limit context size
// Iterate efficiently with async iteration
for await (const peer of await honcho.getPeers()) {
for await (const peer of await honcho.peers()) {
// Process one peer at a time without loading all into memory
}
```

View File

@ -25,7 +25,7 @@ Unlike basic message retrieval, memory-enhanced context:
Automatically manages context to fit within your specified token budget:
```python
context = session.get_context(tokens=2000)
context = session.context(tokens=2000)
```
### Multi-Layered Context
@ -42,7 +42,7 @@ Combines multiple information sources:
Fine-tune what context is included:
```python
context = session.get_context(
context = session.context(
tokens=2000,
include_summaries=True,
include_representation=True,
@ -58,7 +58,7 @@ Provide your agent with rich context for personalized responses:
```python
# Get optimized context
context = session.get_context(tokens=1500)
context = session.context(tokens=1500)
# Use in your LLM prompt
response = llm.generate(
@ -75,10 +75,10 @@ Get context tailored to specific participants:
```python
# Get Alice's perspective
alice_context = session.get_context(peer_id=alice.id)
alice_context = session.context(peer_id=alice.id)
# Get Bob's perspective
bob_context = session.get_context(peer_id=bob.id)
bob_context = session.context(peer_id=bob.id)
```
### Dynamic Context Windows
@ -87,10 +87,10 @@ Adjust context size based on task complexity:
```python
# More context for complex tasks
detailed_context = session.get_context(tokens=4000)
detailed_context = session.context(tokens=4000)
# Minimal context for simple queries
quick_context = session.get_context(tokens=500)
quick_context = session.context(tokens=500)
```
## How It Works
@ -111,7 +111,7 @@ Leave room in your model's context window:
```python
# For a 8K context model
context = session.get_context(tokens=2000) # Leaves room for prompt + response
context = session.context(tokens=2000) # Leaves room for prompt + response
```
### Representation Updates
@ -132,7 +132,7 @@ Context can be cached for repeated queries:
```python
# Cache context for multiple agent calls
cached_context = session.get_context(tokens=2000)
cached_context = session.context(tokens=2000)
# Reuse for multiple related queries
for query in user_queries:

View File

@ -124,7 +124,7 @@ def llm(session, prompt) -> str:
You should expand this function with custom logic, prompts, etc.
"""
messages: list[dict[str, object]] = session.get_context().to_openai(
messages: list[dict[str, object]] = session.context().to_openai(
assistant=assistant
)
messages.append({"role": "user", "content": prompt})
@ -246,7 +246,7 @@ openai = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=MODEL_API_KEY)
The new Honcho peer/session API makes Discord bot integration much simpler and more intuitive. Key patterns we learned:
- **Peer/Session Model**: Users are represented as peers, conversations as sessions
- **Automatic Context Management**: `session.get_context().to_openai()` automatically formats chat history
- **Automatic Context Management**: `session.context().to_openai()` automatically formats chat history
- **Message Storage**: `session.add_messages()` stores both user and assistant messages
- **Representation Queries**: `peer.chat()` enables querying conversation history
- **Helper Functions**: Clean code organization with focused helper functions

View File

@ -128,7 +128,7 @@ response = user.chat("What does the quarterly report say about revenue growth?")
print(response)
# Get context from the uploaded documents for LLM integration
context = session.get_context(tokens=3000)
context = session.context(tokens=3000)
messages = context.to_openai(assistant=assistant)
```
@ -143,7 +143,7 @@ messages = context.to_openai(assistant=assistant)
console.log(response2);
// Get context from the uploaded documents for LLM integration
const context = await session.getContext({ tokens: 3000 });
const context = await session.context({ tokens: 3000 });
const messages = context.toOpenAI(assistant);
})();
```
@ -203,7 +203,7 @@ def upload_document(file_path, description):
def analyze_documents():
"""Get AI analysis of uploaded documents"""
context = session.get_context(tokens=4000)
context = session.context(tokens=4000)
messages = context.to_openai(assistant=assistant)
# Add analysis request
messages.append({
@ -251,7 +251,7 @@ import fs from "fs";
}
async function analyzeDocuments() {
const context = await session.getContext({ tokens: 4000 });
const context = await session.context({ tokens: 4000 });
const messages = context.toOpenAI(assistant);
// Add analysis request
messages.push({

View File

@ -154,10 +154,10 @@ def chatbot(state: State):
session.add_messages([user.message(user_message)])
# Step 2: Get context in OpenAI format with token limit
# get_context() retrieves relevant conversation history
# context() retrieves relevant conversation history
# tokens=2000 limits the context to 2000 tokens to manage costs and fit within model limits
# to_openai() converts it to the format expected by OpenAI's API
messages = session.get_context(tokens=2000).to_openai(assistant=assistant)
messages = session.context(tokens=2000).to_openai(assistant=assistant)
# Step 3: Generate response using the context
response = llm.chat.completions.create(
@ -186,10 +186,10 @@ async function chatbot(state: State) {
await session.addMessages([user.message(userMessage)]);
// Step 2: Get context in OpenAI format with token limit
// getContext() retrieves relevant conversation history
// context() retrieves relevant conversation history
// tokens: 2000 limits the context to 2000 tokens to manage costs and fit within model limits
// toOpenAI() converts it to the format expected by OpenAI's API
const messages = (await session.getContext({ tokens: 2000 })).toOpenAI(assistant);
const messages = (await session.context({ tokens: 2000 })).toOpenAI(assistant);
// Step 3: Generate response using the context
const response = await llm.chat.completions.create({
@ -225,9 +225,9 @@ const graph = new StateGraph(StateAnnotation)
```
</CodeGroup>
### Understanding get_context()
### Understanding context()
The [`get_context()`](/v3/documentation/features/get-context) method retrieves comprehensive conversation context and formats it for your LLM. It automatically:
The [`context()`](/v3/documentation/features/get-context) method retrieves comprehensive conversation context and formats it for your LLM. It automatically:
- **Manages conversation history** - Tracks all messages and determines what's relevant
- **Respects token limits** - Stays within context window constraints without manual counting
@ -241,14 +241,14 @@ The `SessionContext` object always includes fields for messages, summaries, `pee
- **Without `peer_perspective`**: Returns Honcho's omniscient view of `peer_target` (all conclusions and context)
- **With `peer_perspective`**: Returns what `peer_perspective` knows about `peer_target` (perspective-based conclusions and context)
That's it. Call `session.get_context().to_openai(assistant)` and you get properly formatted context tailored for your assistant.
That's it. Call `session.context().to_openai(assistant)` and you get properly formatted context tailored for your assistant.
<Tip>
**Adding System Prompts:** Since `get_context()` returns conversation messages, you can easily prepend custom system instructions. Just add your system prompt to the beginning of the messages array before sending it to your LLM: `[{"role": "system", "content": "..."}, ...context_messages]`.
**Adding System Prompts:** Since `context()` returns conversation messages, you can easily prepend custom system instructions. Just add your system prompt to the beginning of the messages array before sending it to your LLM: `[{"role": "system", "content": "..."}, ...context_messages]`.
</Tip>
<Note>
For more details on all available parameters, see [`get_context() documentation`](/v3/documentation/features/get-context)
For more details on all available parameters, see [`context() documentation`](/v3/documentation/features/get-context)
</Note>
## Chat Loop

View File

@ -251,13 +251,13 @@ Reference the [API Comparison](#api-comparison) to replace your Mem0 API calls w
| **Add messages** | `client.add(messages, user_id=...)` | `session.add_messages([peer.message(...)])` | Session-scoped, triggers reasoning |
| **Add conclusions** | | `peer.conclusions.create([...])` | Direct conclusion or "memory" import, no processing |
| **Search** | `client.search(query, filters={"user_id": ...})` | `peer.search(query)` or `peer.conclusions.query(...)` | Scoped to peer or session |
| **List all** | `client.get_all(filters={"user_id": ...})` | `session.get_messages()` or `peer.conclusions.list()` | Messages or conclusions |
| **List all** | `client.get_all(filters={"user_id": ...})` | `session.messages()` or `peer.conclusions.list()` | Messages or conclusions |
| **Update** | `client.update(memory_id, data=...)` | `honcho.update_message(message, metadata=...)` | Metadata updates only |
| **Delete** | `client.delete(memory_id)` | `peer.conclusions.delete(id)` or `session.delete()` | Conclusion or session-level |
### Honcho-Only Capabilities
Mem0 requires manual assembly of context from `search()` results. Honcho's `session.get_context()` returns a ready-to-use `SessionContext` object with built-in token limits, auto-included summaries, and format helpers (`.to_openai()`, `.to_anthropic()`).
Mem0 requires manual assembly of context from `search()` results. Honcho's `session.context()` returns a ready-to-use `SessionContext` object with built-in token limits, auto-included summaries, and format helpers (`.to_openai()`, `.to_anthropic()`).
<Card title="Get Context" icon="window-restore" href="../../documentation/features/get-context">
Learn more about token-optimized context retrieval
@ -275,8 +275,8 @@ Additional features with **no Mem0 equivalent**:
| Honcho Method | Description | Use Case |
|---------------|-------------|----------|
| `peer.card()` | Stable biographical facts (name, preferences, background) | User profiles, personalization |
| `session.get_representation(peer)` | Cached psychological analysis (mental state, intentions) | Real-time adaptation |
| `session.get_summaries()` | Auto-generated short/long session summaries | Conversation continuity |
| `session.representation(peer)` | Cached psychological analysis (mental state, intentions) | Real-time adaptation |
| `session.summaries()` | Auto-generated short/long session summaries | Conversation continuity |
| `SessionPeerConfig` | Configure observation settings (who learns about whom) | Privacy controls, role-based learning |
## Next Steps

View File

@ -146,7 +146,7 @@ def llm(session, prompt) -> str:
You should expand this function with custom logic, prompts, etc.
"""
messages: list[dict[str, object]] = session.get_context().to_openai(
messages: list[dict[str, object]] = session.context().to_openai(
assistant=assistant
)
messages.append({"role": "user", "content": prompt})
@ -349,7 +349,7 @@ The new Honcho peer/session API makes Telegram bot integration much simpler and
- **Peer/Session Model**: Users are represented as peers, conversations as sessions
- **Chat Type Handling**: Different validation logic for private vs group chats
- **Automatic Context Management**: `session.get_context().to_openai()` automatically formats chat history
- **Automatic Context Management**: `session.context().to_openai()` automatically formats chat history
- **Message Storage**: `session.add_messages()` stores both user and assistant messages
- **Dialectic Queries**: `peer.chat()` enables querying conversation history
- **Command System**: Native Telegram command support with `/start` and `/dialectic`

View File

@ -251,13 +251,13 @@ Reference the [API Comparison](#api-comparison) to replace your Mem0 API calls w
| **Add messages** | `client.add(messages, user_id=...)` | `session.add_messages([peer.message(...)])` | Session-scoped, triggers reasoning |
| **Add conclusions** | | `peer.conclusions.create([...])` | Direct conclusion or "memory" import, no processing |
| **Search** | `client.search(query, filters={"user_id": ...})` | `peer.search(query)` or `peer.conclusions.query(...)` | Scoped to peer or session |
| **List all** | `client.get_all(filters={"user_id": ...})` | `session.get_messages()` or `peer.conclusions.list()` | Messages or conclusions |
| **List all** | `client.get_all(filters={"user_id": ...})` | `session.messages()` or `peer.conclusions.list()` | Messages or conclusions |
| **Update** | `client.update(memory_id, data=...)` | `honcho.update_message(message, metadata=...)` | Metadata updates only |
| **Delete** | `client.delete(memory_id)` | `peer.conclusions.delete(id)` or `session.delete()` | Conclusion or session-level |
### Honcho-Only Capabilities
Mem0 requires manual assembly of context from `search()` results. Honcho's `session.get_context()` returns a ready-to-use `SessionContext` object with built-in token limits, auto-included summaries, and format helpers (`.to_openai()`, `.to_anthropic()`).
Mem0 requires manual assembly of context from `search()` results. Honcho's `session.context()` returns a ready-to-use `SessionContext` object with built-in token limits, auto-included summaries, and format helpers (`.to_openai()`, `.to_anthropic()`).
<Card title="Get Context" icon="window-restore" href="../../documentation/features/get-context">
Learn more about token-optimized context retrieval
@ -275,8 +275,8 @@ Additional features with **no Mem0 equivalent**:
| Honcho Method | Description | Use Case |
|---------------|-------------|----------|
| `peer.card()` | Stable biographical facts (name, preferences, background) | User profiles, personalization |
| `session.get_representation(peer)` | Cached psychological analysis (mental state, intentions) | Real-time adaptation |
| `session.get_summaries()` | Auto-generated short/long session summaries | Conversation continuity |
| `session.representation(peer)` | Cached psychological analysis (mental state, intentions) | Real-time adaptation |
| `session.summaries()` | Auto-generated short/long session summaries | Conversation continuity |
| `SessionPeerConfig` | Configure observation settings (who learns about whom) | Privacy controls, role-based learning |
## Next Steps