Feat/context#3435
Open
JasonW404 wants to merge 18 commits into
Open
Conversation
Introduce fine-grained context management system with three-layer architecture: - Context item projection and history projector for ReAct process persistence - Policy models and selection engine for deterministic context decisions - OpenTelemetry instrumentation and strategy filtering fixes - DB schema migration for history projection fields - Tool call row merging and WorkingMemoryHandler removal
Add context item reduction pipeline with admissibility validation: - Deterministic and semantic reduction strategies - Manager type narrowing fixes - Dynamic message iteration guards - Default strategy changed to FullStrategy for better compatibility
Migrate agent context assembly from backend to SDK layer: - NexentAgent now uses managed context runtime with ContextManager - Backend create_agent_info delegates context component building to SDK - Add SDK functional test skill for Langfuse integration testing
- Update knowledge_base_summary tests to check build_context_components instead of system_prompt (aligns with context manager refactor) - Add build_context_components mock to affected test cases - Update builtin_tools test to verify tools are passed to context All 178 tests in test_create_agent_info.py now pass.
Add builtin_tools to the tools dict passed to prompt templates, ensuring skill script tools (run_skill_script, read_skill_md, etc.) are available in the template rendering context. This aligns with the test expectation in test_create_agent_config_managed_path_includes_builtin_tools_in_context.
Extract the 90KB agent_context.py monolith into a properly structured agent_context/ package with separate modules for each concern: - summary_step.py: SummaryTaskStep and ManagedRunContext data types - budget.py: Budget calculation, cache validation, fingerprint helpers - llm_summary.py: LLM-based summary generation - step_renderer.py: Step rendering and offline compression - previous_compression.py: Previous message compression - current_compression.py: Current message compression - stats_export.py: Statistics export functions - manager.py: ContextManager orchestrator Also includes: - Test loader updates for package structure - Additional test coverage for extracted modules - Import depth fixes - SonarCloud issue fixes All 161 context tests pass. Agent_context tests have pre-existing import issues with smolagents.Tool that are not introduced by this change.
Add Tool and OpenAIServerModel mocks to stubs.py to fix import errors when agent_context tests load manager.py, which imports from nexent.core.models.openai_llm. This resolves the 14 collection errors in test_agent_context/unit/ tests.
…mponent_management - Add agent_id attribute to ConversationRecord mock in test_conversation_db.py to match production code that references ConversationRecord.agent_id - Mock runtime_state_service in agent_run_manager tests to make them environment-independent (tests were failing when Redis was configured locally) - Update strategy test names to reflect FullStrategy as the new default (test_default_returns_full_strategy, test_unknown_strategy_defaults_to_full)
- Restore get_valid_model_ids and get_model_by_model_id_ignore_delete imports in agent_service.py (lost during squash merge from feat/context-wip) - Include builtin_tools (skill script tools) in render_kwargs['tools'] dict in create_agent_info.py so they are available in context components - Use cached builtin_tools variable instead of calling _get_skill_script_tools twice (once for render_kwargs, once for AgentConfig.tools)
Add test/.coverage and test/.coverage.* patterns to prevent coverage data files from being accidentally committed.
- Add runtime_state_service import and helper functions for multi-pod cancel signal coordination - Add get_valid_model_ids usage to filter out deleted models in get_agent_info_impl and list_all_agent_info_impl - Add skill instance filtering to exclude disabled skills from agent configuration - Add tool unavailable_reasons check for soft-deleted selected_model_id - Fix terminal_status variable scope in _stream_agent_chunks finally block - Add stop event handling to mark messages as 'stopped' when stop_event is set Reduces test failures from 29 to 5 in test_agent_service.py
- Add nexent.core.agents.context submodule mocks to fix ModuleNotFoundError - Add conversation_id parameter to test assertion - Implement Redis-based streaming when channel is None but agent is running remotely - Add helper functions for resume status chunks
…res_final_answer_and_adds_memory
…ation - test: add missing ProcessType mock members (STEP_COUNT, TOOL, EXECUTION_LOGS) that caused AttributeError in _stream_agent_chunks chunk parsing, preventing captured_final_answer from being set - security: remove clear-text token logging in inspect_env.py (CodeQL high alert) - refactor: extract shared fingerprint/token_estimate into handlers/_utils.py, eliminating duplication across 8 context handler files - fix: add ClassVar annotation to ItemHandlerRegistry._handlers (CodeQL)
- test__stream_agent_chunks_buffers_tool_chunk: verifies single tool chunk is buffered and flushed in finally block with unit_type='tool' - test__stream_agent_chunks_merges_tool_and_execution_logs: verifies tool + execution_logs are merged into unit_type='tool_call' with combined content - Fixed submit mock to actually invoke fn(*a, **kw) so save_message_unit calls are recorded for assertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.