fix: removing unnecessary code and adding config for observing
This commit is contained in:
parent
933f3bbfee
commit
23e64cd90a
|
|
@ -1,130 +0,0 @@
|
|||
"""
|
||||
Honcho Multi-Tool Example
|
||||
|
||||
Demonstrates using Honcho tools with an Agno agent:
|
||||
- honcho_chat: Ask questions about the conversation (recommended)
|
||||
- honcho_get_context: Retrieve raw session context
|
||||
- honcho_search_messages: Semantic search through messages
|
||||
|
||||
The honcho_chat tool is the recommended way to understand users
|
||||
It reasons over conversation context and provides synthesized insights.
|
||||
|
||||
Environment Variables:
|
||||
LLM_OPENAI_API_KEY: OpenAI API key (matches honcho .env)
|
||||
OPENAI_MODEL: Model to use
|
||||
HONCHO_API_KEY: Required for Honcho API access
|
||||
"""
|
||||
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
|
||||
from honcho import Honcho
|
||||
from honcho_agno import HonchoTools
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Use LLM_OPENAI_API_KEY from honcho .env
|
||||
if llm_key := os.getenv("LLM_OPENAI_API_KEY"):
|
||||
os.environ["OPENAI_API_KEY"] = llm_key
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 70)
|
||||
print("HONCHO TOOLS + AGNO EXAMPLE")
|
||||
print("=" * 70 + "\n")
|
||||
|
||||
# Initialize Honcho client
|
||||
honcho = Honcho(workspace_id="travel-app")
|
||||
|
||||
# Setup Honcho tools - creates peer and session internally
|
||||
# Generate unique session ID to avoid message accumulation across runs
|
||||
honcho_tools = HonchoTools(
|
||||
peer_id="travel-assistant",
|
||||
session_id=str(uuid.uuid4()),
|
||||
honcho_client=honcho,
|
||||
)
|
||||
|
||||
# Create user peer (the toolkit's peer is "travel-assistant")
|
||||
user_peer = honcho.peer("traveler-42")
|
||||
|
||||
# Pre-populate with user's travel preferences
|
||||
print("Adding user's travel preferences to memory...")
|
||||
messages = [
|
||||
"I'm planning a trip to Japan in March",
|
||||
"I love trying authentic local cuisine",
|
||||
"My budget is around $3000 for 10 days",
|
||||
"I prefer ryokans over hotels",
|
||||
"I'm interested in both traditional temples and modern Tokyo",
|
||||
]
|
||||
|
||||
for msg in messages:
|
||||
honcho_tools.session.add_messages([user_peer.message(msg)])
|
||||
print(f" [traveler-42]: {msg[:50]}...")
|
||||
|
||||
print("\n" + "-" * 70 + "\n")
|
||||
|
||||
# Create travel planning agent with memory tools
|
||||
agent = Agent(
|
||||
name="Travel Planner",
|
||||
model=OpenAIChat(id=os.getenv("OPENAI_MODEL", "gpt-4o")),
|
||||
tools=[honcho_tools],
|
||||
description=(
|
||||
"A travel planning expert with access to Honcho memory tools. "
|
||||
"Use honcho_chat to understand the traveler's preferences and travel style."
|
||||
),
|
||||
instructions=[
|
||||
"Use the honcho_chat tool to understand the user's preferences and travel style",
|
||||
"Ask both broad and specific questions like 'What is their travel style?' or 'What is their budget?'",
|
||||
"Only use honcho_get_context or honcho_search_messages if you need raw message history",
|
||||
"Be specific and actionable in your recommendations",
|
||||
],
|
||||
)
|
||||
|
||||
# Run the agent with a planning request
|
||||
print("Asking agent to create a personalized itinerary...\n")
|
||||
response = agent.run(
|
||||
"Create a 3-day Tokyo itinerary for me. Use the honcho_chat tool to ask about "
|
||||
"my budget, accommodation preferences, and interests, then create "
|
||||
"a personalized plan that matches my travel style."
|
||||
)
|
||||
|
||||
# Save the assistant's response to Honcho (using toolkit's peer and session)
|
||||
assistant_response = str(response.content) if response.content else ""
|
||||
if assistant_response:
|
||||
honcho_tools.session.add_messages([honcho_tools.peer.message(assistant_response)])
|
||||
|
||||
print("=" * 70)
|
||||
print("RESPONSE")
|
||||
print("=" * 70)
|
||||
print(response.content)
|
||||
|
||||
# Demonstrate chat (recommended)
|
||||
print("\n" + "=" * 70)
|
||||
print("DIRECT TOOL USAGE: honcho_chat (recommended)")
|
||||
print("=" * 70)
|
||||
chat_result = honcho_tools.honcho_chat(
|
||||
"What are the traveler's key preferences and constraints?"
|
||||
)
|
||||
print(chat_result)
|
||||
|
||||
# Demonstrate search capability
|
||||
print("\n" + "=" * 70)
|
||||
print("DIRECT TOOL USAGE: honcho_search_messages")
|
||||
print("=" * 70)
|
||||
search_result = honcho_tools.honcho_search_messages("budget money cost", limit=5)
|
||||
print(search_result)
|
||||
|
||||
# Show full conversation context
|
||||
print("\n" + "=" * 70)
|
||||
print("DIRECT TOOL USAGE: honcho_get_context")
|
||||
print("=" * 70)
|
||||
print(honcho_tools.honcho_get_context())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -20,6 +20,7 @@ from agno.agent import Agent
|
|||
from agno.models.openai import OpenAIChat
|
||||
|
||||
from honcho import Honcho
|
||||
from honcho.session import SessionPeerConfig
|
||||
from honcho_agno import HonchoTools
|
||||
|
||||
load_dotenv()
|
||||
|
|
@ -49,6 +50,14 @@ def main():
|
|||
assistant_peer = honcho.peer("assistant")
|
||||
session = honcho.session(session_id)
|
||||
|
||||
# Configure observation settings:
|
||||
# - User is observed (assistant builds theory-of-mind of user)
|
||||
# - Assistant is NOT observed (no need for user to model the assistant)
|
||||
session.add_peers([
|
||||
(user_peer, SessionPeerConfig(observe_me=True, observe_others=False)),
|
||||
(assistant_peer, SessionPeerConfig(observe_me=False, observe_others=True)),
|
||||
])
|
||||
|
||||
# Create an agent with memory tools
|
||||
agent = Agent(
|
||||
name="Programming Mentor",
|
||||
|
|
|
|||
|
|
@ -1,115 +0,0 @@
|
|||
"""
|
||||
Tests for Honcho Agno Tools
|
||||
|
||||
Simple tests verifying tool structure, registration, and initialization.
|
||||
These tests use minimal mocking - just enough to avoid network calls.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from honcho_agno import HonchoTools
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_client():
|
||||
"""Create a minimal mock Honcho client."""
|
||||
client = MagicMock()
|
||||
client.peer.return_value = MagicMock()
|
||||
client.session.return_value = MagicMock()
|
||||
return client
|
||||
|
||||
|
||||
class TestInitialization:
|
||||
"""Tests for HonchoTools initialization."""
|
||||
|
||||
def test_initializes_with_client(self, mock_client):
|
||||
"""Test initialization with a provided client."""
|
||||
tools = HonchoTools(
|
||||
peer_id="assistant",
|
||||
session_id="test-session",
|
||||
honcho_client=mock_client,
|
||||
)
|
||||
|
||||
assert tools.honcho is mock_client
|
||||
assert tools.peer_id == "assistant"
|
||||
assert tools.session_id == "test-session"
|
||||
|
||||
def test_default_peer_id(self, mock_client):
|
||||
"""Test default peer_id is 'assistant'."""
|
||||
tools = HonchoTools(honcho_client=mock_client)
|
||||
assert tools.peer_id == "assistant"
|
||||
|
||||
def test_auto_generates_session_id(self, mock_client):
|
||||
"""Test session_id is auto-generated if not provided."""
|
||||
tools = HonchoTools(honcho_client=mock_client)
|
||||
|
||||
assert tools.session_id is not None
|
||||
# Should be valid UUID
|
||||
uuid.UUID(tools.session_id)
|
||||
|
||||
def test_toolkit_name(self, mock_client):
|
||||
"""Test toolkit has correct name."""
|
||||
tools = HonchoTools(honcho_client=mock_client)
|
||||
assert tools.name == "honcho"
|
||||
|
||||
|
||||
class TestToolRegistration:
|
||||
"""Tests verifying tools are properly registered."""
|
||||
|
||||
def test_all_tools_registered(self, mock_client):
|
||||
"""Test all expected tools are registered."""
|
||||
tools = HonchoTools(honcho_client=mock_client)
|
||||
|
||||
registered = [func.name for func in tools.functions.values()]
|
||||
|
||||
assert "honcho_get_context" in registered
|
||||
assert "honcho_search_messages" in registered
|
||||
assert "honcho_chat" in registered
|
||||
assert len(registered) == 3
|
||||
|
||||
def test_tools_are_callable(self, mock_client):
|
||||
"""Test tool methods exist and are callable."""
|
||||
tools = HonchoTools(honcho_client=mock_client)
|
||||
|
||||
assert callable(tools.honcho_get_context)
|
||||
assert callable(tools.honcho_search_messages)
|
||||
assert callable(tools.honcho_chat)
|
||||
|
||||
|
||||
class TestMultiPeerPattern:
|
||||
"""Tests for multi-peer conversation patterns."""
|
||||
|
||||
def test_multiple_toolkits_share_session(self, mock_client):
|
||||
"""Test multiple toolkits can share a session ID."""
|
||||
session_id = "shared-session"
|
||||
|
||||
agent1 = HonchoTools(
|
||||
peer_id="agent-alpha",
|
||||
session_id=session_id,
|
||||
honcho_client=mock_client,
|
||||
)
|
||||
|
||||
agent2 = HonchoTools(
|
||||
peer_id="agent-beta",
|
||||
session_id=session_id,
|
||||
honcho_client=mock_client,
|
||||
)
|
||||
|
||||
assert agent1.session_id == agent2.session_id
|
||||
assert agent1.peer_id != agent2.peer_id
|
||||
|
||||
def test_each_toolkit_has_one_peer(self, mock_client):
|
||||
"""Test each toolkit represents exactly one peer."""
|
||||
tools = HonchoTools(
|
||||
peer_id="my-agent",
|
||||
honcho_client=mock_client,
|
||||
)
|
||||
|
||||
assert tools.peer is not None
|
||||
assert tools.peer_id == "my-agent"
|
||||
# Should not have multiple peer attributes
|
||||
assert not hasattr(tools, "user")
|
||||
assert not hasattr(tools, "assistant_peer")
|
||||
Loading…
Reference in New Issue