Add taxonomy system and refactor agents & ledger models#554
Conversation
…ructure changes - Updated the `robosystems-client` dependency in `pyproject.toml` and `uv.lock` to version 0.2.37. - Introduced a new migration script to rename the `accounts` table to `elements` and added a taxonomy system with new tables for `taxonomies` and `structures`. - Refactored related code to replace references from `accounts` to `elements`, ensuring consistency across the codebase. - Added new models for `Element`, `ElementAssociation`, `Structure`, and `Taxonomy` to support the updated taxonomy structure.
- Created a migration to add `taxonomies` and `structures` tables, enhancing the database schema for taxonomy management. - Updated the `_insert_element` function to include `created_at` and `updated_at` timestamps. - Introduced new API endpoints for CRUD operations on taxonomies, structures, and element associations, improving the taxonomy management capabilities. - Added response models for taxonomies and structures to support the new API functionality.
- Introduced four new taxonomy mapping tools: `get-unmapped-elements`, `suggest-mapping`, `create-mapping-association`, and `get-mapping-summary`, gated by the `roboledger` extension and `EXTENSIONS_ENABLED` flag. - Implemented methods to retrieve tool definitions and execute the new tools, enhancing the taxonomy management capabilities. - Added unit tests to ensure proper registration and dispatching of the taxonomy tools, including checks for availability based on extension settings and read-only mode.
- Introduced a new SQL model `elements.sql` to replace the previous `accounts.sql`, aligning with the updated taxonomy structure. - Updated references in existing SQL files and tests to use `elements` instead of `accounts`, ensuring consistency across the codebase. - Modified the loading and processing logic to accommodate the new terminology, enhancing clarity in the data pipeline. - Added a new function to seed tenant reporting taxonomy, improving the management of shared reporting structures.
- Added `WORKER_API_BASE_URL` environment variable to `compose.yaml` for API access. - Updated `worker.yaml` to include `WORKER_API_BASE_URL` in the CloudFormation template. - Introduced `WorkerAPIClient` for handling HTTP requests from the worker to the API. - Implemented `AgentMappingTask` for autonomous mapping of Chart of Accounts to US GAAP using Bedrock AI. - Added new endpoint for auto-mapping elements in the ledger router. - Removed the `FinancialAgent` class and its associated tests to streamline the agent system. - Added tests for the new `WorkerAPIClient` and `AgentMappingTask` functionalities.
- Removed `WORKER_API_BASE_URL` from environment variables in `compose.yaml` and `worker.yaml`. - Deleted `WorkerAPIClient` as it is no longer needed for API interactions. - Introduced `AgentMappingTask` for autonomous mapping of Chart of Accounts to US GAAP using Bedrock AI. - Added new files for agent mapping tasks and prompts to support the mapping functionality. - Implemented tests for the new `AgentMappingTask` to ensure proper functionality and coverage.
- Introduced a new unified agent protocol with classes for Agent, AgentSpec, AgentResult, and AgentContext to streamline agent definitions across execution contexts. - Added legacy support for existing orchestrator and routers, allowing gradual migration to the new protocol. - Implemented various agent context services, including tool access and credit consumption, to facilitate agent operations. - Created new agent registry for managing agent registrations and lookups. - Developed multiple agent implementations, including CypherAgent for natural language to Cypher query conversion and MappingAgent for autonomous Chart of Accounts to US GAAP mapping. - Enhanced progress reporting and credit consumption mechanisms for better tracking and management during agent execution.
- Updated the agent operations module to implement a unified agent protocol, enhancing dynamic routing and execution capabilities. - Removed legacy components including the context enricher, Cypher agent, and agent registry to streamline the agent framework. - Introduced execution adapters for running agents in different contexts (API and worker). - Enhanced agent registration and metadata handling for improved compatibility and performance. - Updated documentation to reflect changes in the agent protocol and system architecture.
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 2m 9s —— View job PR Review: Add taxonomy system and refactor agents & ledger modelsTodo List:
This is a large, well-structured PR that introduces a solid taxonomy system and cleans up significant agent complexity. Overall the direction is excellent. Below are issues ranging from bugs to design observations. Bugs1. result.metadata["credits_remaining"] = (
tracked_ai._credit_consumer is not None
and getattr(tracked_ai, "_last_remaining", None)
)
2.
Index(
"idx_associations_unapproved",
"approved_by",
postgresql_where="approved_by IS NULL AND suggested_by = 'ai'",
),This index exists in the ORM model but is not created in the migration ( 3. # tracked_ai.py:31
credit_consumer: CreditConsumer, # non-optional Protocol
# api.py:64
credit_consumer = SessionCreditConsumer(db_session) if db_session else None # can be NoneWhen Code Quality Issues4.
from typing import Literal
class CreateTaxonomyRequest(BaseModel):
taxonomy_type: Literal["chart_of_accounts", "reporting", "mapping"]5. The pattern 6. The endpoint returns an untyped 7. timestamp: datetime = field(default_factory=datetime.utcnow) # deprecated in Py3.12
"timestamp": datetime.utcnow().isoformat(), # same issueThe rest of the codebase uses 8. Module docstring in The docstring mentions "Separate from the legacy AgentRegistry (registry.py)" but Design Observations (non-blocking)9. Migration seeds data inline ( seed_reporting_taxonomy(conn)Calling 10. Missing UPDATE/DELETE endpoints for Taxonomy and Structure ( The router supports 11. suggested_by="cowork",This should probably reflect the actual tool/agent performing the suggestion (e.g. 12. def _get_all_agents(self) -> dict[str, Agent]:
agents = {}
for agent_type in list_agents():
agents[agent_type] = get_agent(agent_type)Since agents are stateless, this is functionally safe, but instantiating on every 13. session = SessionFactory()
try:
service = CreditService(session)
result = service.consume_ai_tokens(...)
return float(result.get("credits_consumed", 0))There's no SummaryThe taxonomy system is well-modeled with a clean separation between shared (public schema) GAAP elements and per-tenant CoA/mapping data. The agent refactor achieves its stated goals: stateless agents, protocol-based service injection, and clean separation between domain logic (implementations/) and execution wiring (adapters/). The migration is comprehensive and correctly handles tenant schema iteration. The most critical issues to address before merge are #1 (broken |
- Added a new index for unapproved element associations in the database migration to improve query performance. - Updated the suggested_by field in the CreateMappingAssociationTool to use 'ai' instead of 'cowork' for better tracking of AI-generated associations. - Refactored agent context and registry components to streamline the agent protocol, including optional credit consumption handling in TrackedAIClient. - Improved metadata handling in the agent API to indicate whether credit tracking is enabled.
|
@claude can you continue to review including the new commit |
|
Claude finished @jfrench9's task in 2m 13s —— View job Todo List:
Updated PR Review: Add taxonomy system and refactor agents & ledger modelsThe new commit ( Fixed in
|
Summary
This PR introduces a comprehensive taxonomy system for financial data classification and simultaneously refactors the agent architecture into a unified, modular design. The ledger model layer is renamed from "accounts" to "elements" to support a more flexible, taxonomy-driven data model.
Key Accomplishments
Taxonomy System
rename_accounts_to_elements_add_taxonomy)robosystems/config/taxonomy/seed.py) providing a canonical set of financial taxonomy definitionsrobosystems/routers/ledger/taxonomies.py) with corresponding Pydantic API modelstaxonomy_tools.pyto expose taxonomy mapping capabilities to the graph-based MCP agent framework, integrated via the tools managerLedger Model Refactor: Accounts → Elements
accountmodel toelementacross the entire codebase (ORM models, API schemas, dbt models, QuickBooks adapter, routers, and tests)element_associationmodel for many-to-many relationships between elements and taxonomiesstructuremodel to represent hierarchical taxonomy structuresAgent System Overhaul
base.pywith a cleaner base class; removed legacycontext.py,registry.py,cypher_agent.py, andfinancial.pyagent_context.py— lightweight, well-scoped execution contextagent_registry.py— decorator-based agent registration (@register_taskpattern)adapters/— separated API, worker, and worker task adapters for clean integration boundariesimplementations/— agent implementations (cypher, mapping) organized by domaincredit_consumer.py,progress.py,tracked_ai.py,tool_access.py— composable concerns extracted into single-responsibility modules@register_taskdecoratorsClient & Dependencies
robosystems-clientto0.2.37cryptographyfrom46.0.5to46.0.6Breaking Changes
accountstable toelementsand adds new taxonomy-related tables. Must be applied before deployment.Accountmodel removed: All references toAccountORM model are replaced byElement. Any external code depending on the old model or import paths will break.context.py,registry.py,cypher_agent.py,financial.py) are deleted. Any external references to these modules must be updated to the newimplementations/andadapters/paths.Testing Notes
test_context.py,test_registry.py,test_financial.pyInfrastructure Considerations
🤖 Generated with Claude Code
Branch Info:
feature/taxonomy-systemmainCo-Authored-By: Claude noreply@anthropic.com