honcho/tests/bench
doria 7a9746ca8b
Peer Cards (#180)
* chore: fill out missing metadata inputs in python sdk

* feat: add get_peer_config to python sdk, thoroughly document ts sdk and remove bad client usage

* feat: zod
chore: update tests
chore: bump version, changelog

* chore: python sdk version bump and changelog

* [WIP] feat: combine search methods and rework endpoint to include limit param

* chore: test new stainless config with library

* nits: coderabbit

* Merge branch 'ben/sdk-improvements' into ben/search-rrf

* chore: pre-commit hooks cleanup

* feat: thoroughly document observation config

* Update sdks/python/src/honcho/peer.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: v1.3.0

* feat: update version to 2.2.0 and enhance search functionality with arbitrary filters

- Remove unused config variables
- Added arbitrary filters to all search endpoints.
- Pluralize `filters` everywhere in SDKs for consistency
- Updated documentation and changelog to reflect these changes.

* expose core client in TS and Python SDKs (#150)

* expose core client from sdks

* align text

* fix: resolve get_effective_observe me race condition, default peer config (#176)

* fix: resolve get_effective_observe me race condition, default peer config

* fix: preserve custom config even after leaving

* chore: test cases, enqueue types

* Update sdks/typescript/package.json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: doria <93405247+dr-frmr@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: formatting

* chore: revert undesired changes to v1 spec, clean up docs, coderabbit

* feat: better search docs, fix worker.ts

* fix: correctly make ts params optional in cases, update docs

* chore: coderabbit

* chore: remove spurious package-lock

* feat: [WIP] introduce peer cards

* chore: remove search.mdx

* chore: clean up deriver

* feat: peer cards working in deriver

* feat: add basic peer_card_bench

* feat: refine peer card prompt, add mini-benchmark, switch to gpt-5-nano

* refactor: update peer card handling in dialectic functions and improve error handling

- Enhanced `get_peer_card` function to handle `ResourceNotFoundException`.
- Updated `dialectic_call` and `dialectic_stream` to accept `peer_card` and `target_peer_card` parameters.
- Modified prompt generation to include peer card information.
- Cleaned up whitespace in several files for consistency.

* chore: update mirascope dependency version in configuration files

- Bumped mirascope version from 1.25.1 to 1.25.5 in pyproject.toml and uv.lock.
- Added a note in config.py regarding peer card output token handling.
- Removed unnecessary comments in clients.py for clarity.

* fix: [coderabbit] improve error handling in set_peer_card and enhance logging

- Added a check in `set_peer_card` to raise `ResourceNotFoundException` if the peer does not exist.
- Updated logging in `CertaintyReasoner` to capture exceptions with Sentry when enabled.
- Refined logging messages for clarity and consistency across various functions.
- Cleaned up whitespace and formatting in several files for improved readability.

* refactor: update working representation handling and improve metadata key usage

- Introduced constants for representation collection names to enhance clarity and maintainability.
- Updated function signatures in `get_working_representation` and `set_working_representation` to require `session_name`.
- Simplified metadata key determination logic by using constants instead of hardcoded strings.
- Removed legacy fallback logic for working representation data retrieval.
- Refactored `save_working_representation_to_peer` to utilize the new `set_working_representation` function for improved code reuse.

* chore: update configuration files and enhance working representation settings

- Added new peer card settings and context token limits to `.env.template`, `config.toml.example`, and documentation.
- Introduced `WORKING_REPRESENTATION_MAX_OBSERVATIONS` to `DeriverSettings` for better control over observation storage.
- Updated `set_working_representation` to merge new observations while respecting the maximum limit.
- Improved docstrings for clarity and consistency across functions.

* feat: introduce LLMError exception and enhance error handling in deriver

- Added LLMError exception to handle failures in LLM calls, normalizing inputs into a JSON-serializable format.
- Updated CertaintyReasoner to raise LLMError on exceptions during LLM function calls.
- Enhanced QueueManager to log LLMError occurrences and re-queue messages appropriately.
- Modified test runner to support asynchronous operations and improved output formatting for test results.
- Updated test cases to include session information for better context.

* feat: add __repr__ method to QueueItem for improved string representation

- Implemented a __repr__ method in the QueueItem class to provide a clear and informative string representation of its attributes.
- Updated timeout handling in TestRunner to default to 10000.0 seconds when timeout_seconds is not set, enhancing robustness in polling operations.

* refactor: update peer card data structure and improve handling in related functions

- Changed return type of `get_peer_card` and `set_peer_card` to use `list[str]` instead of `str | None`.
- Updated `peer_card_call` and related functions to accommodate the new list structure for peer cards.
- Introduced `PeerCardQuery` model to standardize responses from peer card queries.
- Adjusted prompt generation in `peer_card_prompt` to reflect the new data structure.
- Modified benchmark tests to align with the updated peer card handling.

* refactor: adjust peer card output token settings and update related functions

- Increased `PEER_CARD_MAX_OUTPUT_TOKENS` from 2000 to 4000 in `DeriverSettings`.
- Updated `critical_analysis_call` to use `json_mode` and removed unused parameters.
- Modified benchmark tests to utilize the new `PEER_CARD_MAX_OUTPUT_TOKENS` setting.
- Removed obsolete `add_dislike.json` test file.

* refactor: update peer card handling in critical analysis and dialectic prompts

- Changed `peer_card` parameter type from `str | None` to `list[str] | None` in `critical_analysis_call` and related functions.
- Simplified error handling in `process_representation_task` by removing redundant try-except block.
- Updated prompt generation in `critical_analysis_prompt` and `dialectic_prompt` to format `peer_card` as a string with newlines.
- Adjusted benchmark tests to reflect changes in peer card structure and output formatting.

* refactor: update peer card test cases to use list structure

- Modified test cases in `test_representation_crud.py` to reflect the change in `peer_card` parameter type from `str` to `list[str]`.
- Updated assertions to accommodate the new list format for setting and retrieving peer cards.
- Ensured that tests for missing peers correctly handle the list input format.

* fix: improve formatting of peer card output in prompts

- Updated `peer_card_prompt` to join `old_peer_card` list elements with newlines for better readability.
- Removed outdated comment in `dialectic_prompt` regarding handling of non-existent cards.

* chore: [coderabbit] enhance docstring and logging in prompts and queue manager

- Updated the docstring in `critical_analysis_prompt` to provide detailed type annotations for parameters.
- Improved logging in `chat` to differentiate between single and multiple retrieved peer cards.
- Adjusted logging format in `QueueManager` to use a more structured approach for shutdown messages.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Rajat Ahuja <rahuja445@gmail.com>
2025-08-12 17:39:08 -04:00
..
peer_card_tests Peer Cards (#180) 2025-08-12 17:39:08 -04:00
tests Peer Cards (#180) 2025-08-12 17:39:08 -04:00
README.md Peer Cards (#180) 2025-08-12 17:39:08 -04:00
harness.py fix: Various performance and linting improvements (#170) 2025-07-28 17:36:14 -04:00
peer_card_bench.py Peer Cards (#180) 2025-08-12 17:39:08 -04:00
run_tests.py Peer Cards (#180) 2025-08-12 17:39:08 -04:00

README.md

Honcho Development Harness

This directory contains a development harness script that makes it easy to run Honcho locally with a Docker database.

Overview

The harness.py script orchestrates the complete Honcho development environment:

  1. Database Setup: Starts a PostgreSQL database in Docker with a configurable port
  2. Database Provisioning: Runs Alembic migrations to set up the database schema
  3. Configuration: Uses environment variables to configure Honcho's database connection
  4. Service Startup: Starts both the FastAPI server and deriver process
  5. Configuration Verification: Prints the actual configuration that Honcho is using
  6. Monitoring: Provides real-time logs from all services
  7. Cleanup: Gracefully shuts down all services when stopped

Prerequisites

  • Python 3.11+
  • Docker and Docker Compose
  • Honcho project dependencies installed (uv sync)

Usage

Basic Usage

Run the harness with default settings (database on port 5433):

python tests/bench/harness.py

Custom Database Port

Run with a custom database port:

python tests/bench/harness.py --port 5434

Custom Project Root

If running from a different directory:

python tests/bench/harness.py --project-root /path/to/honcho

Command Line Options

  • --port: Port for the PostgreSQL database (default: 5433)
  • --project-root: Path to the Honcho project root (default: current directory)

What Gets Started

When you run the harness, it will start:

  1. PostgreSQL Database: Running in Docker on the specified port
  2. FastAPI Server: Available at http://localhost:8000
  3. API Documentation: Available at http://localhost:8000/docs
  4. Deriver Process: Background worker for processing messages

Configuration

The harness uses environment variables to configure Honcho's database connection:

  • DB_CONNECTION_URI: Set to postgresql+psycopg://testuser:testpwd@localhost:{port}/honcho

The script will print the actual configuration that Honcho is using after the FastAPI server starts. This gives you complete visibility into how Honcho's configuration system resolved the settings from environment variables, config files, and defaults.

Stopping the Services

Press Ctrl+C to gracefully stop all services. The harness will:

  1. Stop the FastAPI server and deriver processes
  2. Stop the Docker database container
  3. Clean up temporary files (Docker Compose configuration)

Troubleshooting

Database Connection Issues

If the database fails to start or connect:

  1. Check if port 5433 (or your custom port) is already in use
  2. Ensure Docker is running
  3. Try a different port: --port 5434

Configuration Issues

The script will print the actual configuration being used. If you see unexpected values:

  1. Check if you have a config.toml file that might be overriding environment variables
  2. Verify that the environment variables are being set correctly
  3. Check the Honcho configuration documentation for precedence rules

Integration with CI/CD

This harness can be used in CI/CD pipelines for integration testing. The script will:

  • Use temporary directories for isolation
  • Clean up all resources on exit
  • Provide clear error messages for debugging
  • Exit with appropriate status codes
  • Use environment variables for configuration (no file conflicts)

Test Runner

The run_tests.py script executes JSON-formatted tests against a running Honcho instance. The harness must be running.

Running Tests

  1. Start Honcho using the harness:

    python tests/bench/harness.py
    
  2. In another terminal, run the tests:

    # Run all tests
    python tests/bench/run_tests.py
    
    # Run a specific test
    # Test judge uses claude 3.5 sonnet
    python tests/bench/run_tests.py --test 1.json
    

Test Workflow

For each test, the runner:

  1. Creates a workspace for the test
  2. Adds all messages from the JSON to sessions
  3. Waits for deriver queue to be empty
  4. Executes queries as .chat() calls
  5. Judges responses using expected_response field

Test JSON Format

Tests are defined in JSON files with this structure:

{
    "sessions": {
        "session1": {
            "messages": [
                {
                    "peer": "alice",
                    "content": "Hello, how are you?"
                },
                {
                    "peer": "bob",
                    "content": "I'm good, thank you!"
                }
            ]
        }
    },
    "queries": [
        {
            "query": "How is Bob doing?",
            "expected_response": "Good",
            "session": "session1",  // optional
            "peer": "alice"         // optional
        }
    ]
}

Command Line Options

  • --tests-dir: Directory containing JSON test files (default: tests/bench/tests)
  • --test: Run a specific test file
  • --honcho-url: URL of running Honcho instance (default: http://localhost:8000)
  • --anthropic-api-key: Anthropic API key for response judging, uses LLM_ANTHROPIC_API_KEY if not given
  • --timeout: Timeout for deriver queue to empty (default: 60 seconds)