Single prompt tom#89
Conversation
WalkthroughThe 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
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
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
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
- The docstring at line 106 has a minor typo ("Proces" → "Process").
- If
parse_xml_contentencounters 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
- The hard-coded model
"claude-3-5-haiku-20241022"may be temporary or environment-specific. Confirm it's correct and stable for your deployment.- 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 mirrorsget_tom_inference; consider logging the chosen method (methodargument) 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:
- Is uv installed in the development environment?
- 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 configurationSECRET_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
📒 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 introducedget_tom_inferenceandget_user_representation.
19-20: Verify default environment variable defaults
Defaulting bothTOM_METHODandUSER_REPRESENTATION_METHODto"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 changesrc/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
RaisingValueErroris 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:
- Is this increase necessary for the current use case?
- Have you tested the impact on response time?
- 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 ofOPENAI_API_KEYwith a descriptive comment ("# Used for vector embeddings") and the newANTHROPIC_API_KEYwith 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 togit@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 newuvtool, and it updates the minimum poetry version to0.4.9. This ensures contributors are aware of the revised dependency stack.
32-33: Clarified virtual environment setup.
The instruction now clearly explains thatuvwill create a virtual environment, simplifying dependency isolation for contributors.
39-40: Dependency sync command updated.
The addition of theuv synccommand streamlines setting up dependencies. Double-check that all scripts and automation reflect this change.
68-72: Enhanced environment variable configuration.
The.envsnippet now explicitly documents the purpose of bothOPENAI_API_KEYandANTHROPIC_API_KEY, ensuring clarity.
92-93: Updated API launch command.
Switching tofastapi dev src/main.pymakes 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 usesuvand update the minimum poetry version to0.4.9, keeping the toolchain documentation consistent with other files.
44-45: Updated virtual environment instructions.
Clarifying thatuvautomatically creates the virtual environment aids new contributors in setup.
51-52: Streamlined dependency synchronization.
The inclusion of theuv synccommand in the setup instructions simplifies dependency management.
80-84: Consistent environment variable documentation.
The revised snippet showingOPENAI_API_KEYandANTHROPIC_API_KEYaligns perfectly with the changes in.env.template.
105-106: New API launch command verified.
Transitioning to the commandfastapi dev src/main.pyensures consistency with the overall new setup documentation.
There was a problem hiding this comment.
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_metamessagefunction 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:
- Adding a docstring explaining the limit
- Making the limit configurable
- 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:
- It doesn't handle malformed XML
- 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:
metamessage_typein themetamessagetablepublic_idin theuser,session, andapptablesExample 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
📒 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.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
CHANGELOG.md (2)
8-9: Suggestion: Add Release Date for ConsistencyThe 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 DescriptionsThe "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
📒 Files selected for processing (1)
CHANGELOG.md(1 hunks)
🔇 Additional comments (1)
CHANGELOG.md (1)
17-19: Review: 'Fixed' Section UpdateThe "Fixed" section now indicates that self-hosting documentation and the README have been updated to refer to
uvinstead ofpoetry. This aligns well with the broader changes mentioned in the PR objectives and the AI summary.
* 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>
Fixes dev-559
Summary by CodeRabbit
New Features
Documentation
Chores