Skip to content

Single prompt tom#89

Merged
VVoruganti merged 14 commits into
mainfrom
single-prompt-tom
Feb 25, 2025
Merged

Single prompt tom#89
VVoruganti merged 14 commits into
mainfrom
single-prompt-tom

Conversation

@VVoruganti

@VVoruganti VVoruganti commented Feb 19, 2025

Copy link
Copy Markdown
Collaborator

Fixes dev-559

Summary by CodeRabbit

  • New Features

    • Extended API response capacity for richer interactions.
    • Enhanced conversation processing with improved inference and user representation—integrating new capabilities.
  • Documentation

    • Revised setup, contribution, and self-hosting guides to align with updated tooling and repository structure.
    • Refreshed platform descriptions to highlight enhanced user interaction and infrastructure insights.
  • Chores

    • Streamlined internal configuration and development startup commands for a smoother workflow.

@coderabbitai

coderabbitai Bot commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request updates configuration, documentation, and source code. It revises environment variables by adding new API keys and removing deprecated ones, and changes the start command from a Poetry-based process to a UV-driven one. The documentation is overhauled to reflect new dependency management, updated API launch commands, and rebranding of the Honcho platform. In the source code, message processing is restructured, the token limit increased, and new modular functions are added for theory-of-mind inference and user representation, including integration with the Anthropic API.

Changes

File(s) Change Summary
.env.template, .vscode/tasks.json Updated environment variables with added keys (ANTHROPIC_API_KEY, SECRET_KEY, TOM_METHOD, USER_REPRESENTATION_METHOD), removed deprecated keys (LOGFIRE_TOKEN, AUTH_SERVICE_URL), and modified the start command from a Poetry-based to a uv-based command.
CONTRIBUTING.md, docs/README.md, docs/contributing/self-hosting.mdx, docs/getting-started/introduction.mdx Revised setup instructions and dependency references (switching from Poetry to uv and yarn to pnpm), updated API launch commands, and rebranded/restructured content to align with new development practices.
src/agent.py, src/deriver/consumer.py, src/deriver/tom/(init, conversational, single_prompt).py Increased token limit in Dialectic.call; restructured message processing with new helper functions (get_chat_history, process_user_message); added modular functions for theory-of-mind inference and user representation supporting both conversational and single prompt flows with Anthropic API integration.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Consumer (process_user_message)
    participant H as History (get_chat_history)
    participant T as TOM Dispatcher
    participant R as User Representation

    U->>C: Send message
    C->>H: Retrieve chat history
    H-->>C: Return chat history
    C->>T: Request TOM inference
    T-->>C: Return inference result
    C->>R: Request user representation
    R-->>C: Return user representation
    C-->>U: Deliver processed AI response
Loading
sequenceDiagram
    participant D as TOM Dispatcher
    participant Conv as Conversational Module
    participant SP as Single Prompt Module

    D->>D: Evaluate method parameter
    alt method = conversational
        D->>Conv: Call get_tom_inference_conversational
    else method = single_prompt
        D->>SP: Call get_tom_inference_single_prompt
    end
Loading

Poem

Hopping through code in the night,
I tweak and test with all my might.
New keys and commands, a joyful spree,
Docs reborn, a fresh decree.
As a rabbit, I dance in lines so bright 🥕✨
Cheering the changes with delight.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (9)
src/deriver/consumer.py (2)

39-60: Consider handling empty chat histories
If the session has no prior messages, this function returns an empty string. Ensure downstream steps (like inference) won't break or degrade when there's no history available.


95-193: Fix spelling in docstring and validate XML parse output

  1. The docstring at line 106 has a minor typo ("Proces" → "Process").
  2. If parse_xml_content encounters malformed or missing tags, the returned strings could be empty, silently affecting downstream logic. Consider adding checks or logs to handle or surface these cases.
src/deriver/tom/single_prompt.py (1)

1-188: Validate custom model name and consider externalizing prompts

  1. The hard-coded model "claude-3-5-haiku-20241022" may be temporary or environment-specific. Confirm it's correct and stable for your deployment.
  2. The large system prompts could be extracted to a separate file or template for easier maintenance and updates, reduce inline clutter, and improve readability.
src/deriver/tom/__init__.py (1)

18-30: Maintain clarity in logs
This function closely mirrors get_tom_inference; consider logging the chosen method (method argument) inside the function for improved debugging and tracing.

src/main.py (1)

96-99: Add version prefix and response model to the health check endpoint.

The health check endpoint should follow the same versioning pattern as other endpoints and have a documented response model.

Apply this diff to improve the endpoint:

-@app.get("/health")
-async def healthcheck():
-    return "OK"
+@app.get("/v1/health", response_model=str, description="Health check endpoint")
+async def healthcheck() -> str:
+    return "OK"
.vscode/tasks.json (1)

7-7: Verify the uv command and consider error handling.

The command has been updated to use uv instead of Poetry. While this aligns with the documentation changes, consider adding error handling.

Apply this diff to improve error handling:

-      "command": "uv sync && uv run fastapi dev src/main.py",
+      "command": "uv sync || exit 1 && uv run fastapi dev src/main.py",

Please verify:

  1. Is uv installed in the development environment?
  2. Have you tested the command on different platforms (Windows, Linux, macOS)?
.env.template (1)

14-14: Introduction of SECRET_KEY without a default value.
A new configuration SECRET_KEY= has been added without a provided value. Ensure that production setups securely assign a value and that documentation highlights its importance.

docs/README.md (1)

12-15: Fenced code block language specification recommended.
For improved markdown lint compliance, consider adding a language identifier (e.g., bash) to the fenced code block starting at line 12 (and similarly for other code blocks).

Proposed diff:

-```
+```bash
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

13-13: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

docs/getting-started/introduction.mdx (1)

10-17: Enhanced API capabilities narrative.
The expanded explanation covering the Storage and Insights APIs now provides detailed context. Consider revisiting phrases like "social cognition and deeper understanding" for stylistic refinement if needed.

🧰 Tools
🪛 LanguageTool

[style] ~10-~10: Consider an alternative adjective to strengthen your wording.
Context: ...ers AI agents with social cognition and deeper understanding of their users. The API ...

(DEEP_PROFOUND)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2a1bb1 and b47071a.

📒 Files selected for processing (12)
  • .env.template (1 hunks)
  • .vscode/tasks.json (1 hunks)
  • CONTRIBUTING.md (6 hunks)
  • docs/README.md (2 hunks)
  • docs/contributing/self-hosting.mdx (4 hunks)
  • docs/getting-started/introduction.mdx (1 hunks)
  • src/agent.py (1 hunks)
  • src/deriver/consumer.py (4 hunks)
  • src/deriver/tom/__init__.py (1 hunks)
  • src/deriver/tom/conversational.py (2 hunks)
  • src/deriver/tom/single_prompt.py (1 hunks)
  • src/main.py (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/README.md

8-8: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


13-13: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 LanguageTool
docs/getting-started/introduction.mdx

[style] ~10-~10: Consider an alternative adjective to strengthen your wording.
Context: ...ers AI agents with social cognition and deeper understanding of their users. The API ...

(DEEP_PROFOUND)

🔇 Additional comments (23)
src/deriver/consumer.py (3)

12-12: Imports look good
No issues with referencing the newly introduced get_tom_inference and get_user_representation.


19-20: Verify default environment variable defaults
Defaulting both TOM_METHOD and USER_REPRESENTATION_METHOD to "single_prompt" might alter preexisting behavior if the codebase previously assumed "conversational". Confirm that this is intended and won't cause regressions.


93-94: No functional change

src/deriver/tom/__init__.py (2)

1-2: Imports look good
No concerns with referencing 'conversational' and 'single_prompt' modules.


4-16: Check for method consistency
Raising ValueError is fine for invalid methods. Verify that only "conversational" and "single_prompt" are expected. If new methods evolve, you might want to log or handle them more gracefully.

src/agent.py (1)

76-76: Verify the impact of increasing max_tokens.

The token limit has been doubled from 150 to 300 for non-streaming API calls. While this allows for longer responses, it may impact response time and cost.

Please verify:

  1. Is this increase necessary for the current use case?
  2. Have you tested the impact on response time?
  3. Have you considered the cost implications?
src/deriver/tom/conversational.py (1)

19-20: LGTM! Function names are now more descriptive.

The renaming of functions to include "conversational" in their names better reflects their purpose and suggests a more modular approach with different implementations.

Also applies to: 85-86

.env.template (1)

5-6: New API key configurations added.
The addition of OPENAI_API_KEY with a descriptive comment ("# Used for vector embeddings") and the new ANTHROPIC_API_KEY with its intended usage improves clarity regarding API key purposes.

docs/README.md (3)

1-1: Rebranded title confirmed.
The title update to "# Honcho Docs" clearly communicates the rebranding effort.


3-3: Documentation build tool specification clarified.
The statement "These docs are built using Next.js via mintlify" accurately informs users of the build process.


9-10: Repository URL update.
The updated clone command now points to git@github.com:plastic-labs/honcho.git, which reflects the new repository structure. Confirm that all related documentation has been updated accordingly.

docs/getting-started/introduction.mdx (1)

4-4: Updated document description.
The new description "The identity layer for the agentic world" effectively repositions Honcho’s focus.

docs/contributing/self-hosting.mdx (5)

13-16: Updated dependency information.
The guide now specifies that Honcho is developed using Python and the new uv tool, and it updates the minimum poetry version to 0.4.9. This ensures contributors are aware of the revised dependency stack.


32-33: Clarified virtual environment setup.
The instruction now clearly explains that uv will create a virtual environment, simplifying dependency isolation for contributors.


39-40: Dependency sync command updated.
The addition of the uv sync command streamlines setting up dependencies. Double-check that all scripts and automation reflect this change.


68-72: Enhanced environment variable configuration.
The .env snippet now explicitly documents the purpose of both OPENAI_API_KEY and ANTHROPIC_API_KEY, ensuring clarity.


92-93: Updated API launch command.
Switching to fastapi dev src/main.py makes the local launch process more intuitive. Please verify that this new command functions as intended across environments.

CONTRIBUTING.md (6)

6-6: Contribution workflow clarification.
The instruction to indicate a feature or bug fix in progress is clearly communicated.


25-28: Dependency tool and version updates noted.
The changes now reflect that Honcho uses uv and update the minimum poetry version to 0.4.9, keeping the toolchain documentation consistent with other files.


44-45: Updated virtual environment instructions.
Clarifying that uv automatically creates the virtual environment aids new contributors in setup.


51-52: Streamlined dependency synchronization.
The inclusion of the uv sync command in the setup instructions simplifies dependency management.


80-84: Consistent environment variable documentation.
The revised snippet showing OPENAI_API_KEY and ANTHROPIC_API_KEY aligns perfectly with the changes in .env.template.


105-106: New API launch command verified.
Transitioning to the command fastapi dev src/main.py ensures consistency with the overall new setup documentation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/deriver/consumer.py (4)

23-23: Address the FIXME comment.

The comment indicates potential safety concerns that need to be addressed.

Would you like me to help analyze the safety implications of the add_metamessage function and propose improvements?


40-60: Document the message limit and consider pagination.

The function retrieves the last 10 messages, but this limit isn't documented. Consider:

  1. Adding a docstring explaining the limit
  2. Making the limit configurable
  3. Adding pagination for larger history retrieval

Here's a suggested improvement:

 async def get_chat_history(db, session_id, message_id) -> str:
+    """Retrieve chat history for a session.
+    
+    Args:
+        db: Database session
+        session_id: Session identifier
+        message_id: Current message ID
+    
+    Returns:
+        str: Last 10 messages formatted as 'human: message' or 'ai: message'
+    """
+    HISTORY_LIMIT = 10  # Consider making this configurable
     subquery = (
         select(models.Message.id)
         .where(models.Message.public_id == message_id)
         .scalar_subquery()
     )
     messages_stmt = (
         select(models.Message)
         .where(models.Message.session_id == session_id)
         .order_by(models.Message.id.desc())
         .where(models.Message.id < subquery)
-        .limit(10)
+        .limit(HISTORY_LIMIT)
     )

34-37: Enhance XML parsing robustness.

The current XML parsing implementation could be more robust:

  1. It doesn't handle malformed XML
  2. It uses regex for parsing XML which can be unreliable

Consider using a proper XML parser:

+from xml.etree import ElementTree
+from io import StringIO
+
 def parse_xml_content(text, tag):
+    """Parse XML content safely.
+    
+    Args:
+        text: XML text to parse
+        tag: Tag name to extract
+    
+    Returns:
+        str: Content within the tag or empty string if not found
+    """
+    try:
+        # Wrap content in root element to handle multiple tags
+        wrapped = f"<root>{text}</root>"
+        tree = ElementTree.parse(StringIO(wrapped))
+        element = tree.find(tag)
+        return element.text.strip() if element is not None else ""
+    except (ElementTree.ParseError, AttributeError):
+        return ""
-    pattern = f"<{tag}>(.*?)</{tag}>"
-    match = re.search(pattern, text, re.DOTALL)
-    return match.group(1).strip() if match else ""

130-147: Optimize user representation query performance.

The complex join query for fetching user representation could benefit from an index to improve performance.

Consider adding an index on the following columns:

  1. metamessage_type in the metamessage table
  2. public_id in the user, session, and app tables

Example SQL for adding indexes:

CREATE INDEX idx_metamessage_type ON metamessage(metamessage_type);
CREATE INDEX idx_user_public_id ON user(public_id);
CREATE INDEX idx_session_public_id ON session(public_id);
CREATE INDEX idx_app_public_id ON app(public_id);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bb637a and 6b7919a.

📒 Files selected for processing (1)
  • src/deriver/consumer.py (4 hunks)
🔇 Additional comments (2)
src/deriver/consumer.py (2)

12-12: LGTM!

Clean import of the new TOM-related functions.


19-20: LGTM!

Good practice setting default values for environment variables.

Comment thread src/deriver/consumer.py
Comment thread src/deriver/consumer.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
CHANGELOG.md (2)

8-9: Suggestion: Add Release Date for Consistency

The new version header ## [0.0.16] is correctly added, but notice that previous versions (e.g., ## [0.0.14] — 2024-11-14) include a release date. For consistency and better historical tracking, consider appending the release date here as well.

-## [0.0.16]
+## [0.0.16] — YYYY-MM-DD

10-16: Review: Clarify 'Changed' Section Descriptions

The "Changed" section now lists:

  • A new cognitive architecture for the Deriver that only updates on user messages and enhances confidence scores for known facts.
  • An increase of the Dialectic API token cutoff from 150 to 300 tokens.

While these bullet points capture the changes, you might consider expanding the descriptions or adding contextual details (such as the rationale or expected impact) to help readers quickly understand the significance of these changes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7919a and 66792bb.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🔇 Additional comments (1)
CHANGELOG.md (1)

17-19: Review: 'Fixed' Section Update

The "Fixed" section now indicates that self-hosting documentation and the README have been updated to refer to uv instead of poetry. This aligns well with the broader changes mentioned in the PR objectives and the AI summary.

@VVoruganti VVoruganti merged commit e68acea into main Feb 25, 2025
@VVoruganti VVoruganti deleted the single-prompt-tom branch February 25, 2025 00:12
This was referenced Mar 25, 2025
@coderabbitai coderabbitai Bot mentioned this pull request May 27, 2025
This was referenced Jun 6, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jun 11, 2025
This was referenced Jun 23, 2025
Closed
ranc1 pushed a commit to ranc1/honcho that referenced this pull request Apr 16, 2026
* Add TOM method switching

* Add system prompt and note on format

* Add persistence tweaks

* Specify format for each section of user representation

* Parse XML tags before saving representation metamessage

* Clean up

* Use Claude 3.5 Haiku and refine prompt

* Simplify message processing

* chore: update token limit on dialectic and model for deriver

* chore: Update to Contributing Docs and .env template

* Contributing Docs

* chore: Add Deriver Template Variables

* chore: Remove healthcheck endpoint

* chore: Changelog updates

---------

Co-authored-by: Daniel Balcells <dbalcells@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants