Skip to content

Feat/context#3435

Open
JasonW404 wants to merge 18 commits into
developfrom
feat/context
Open

Feat/context#3435
JasonW404 wants to merge 18 commits into
developfrom
feat/context

Conversation

@JasonW404

Copy link
Copy Markdown
Member

No description provided.

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.
Copilot AI review requested due to automatic review settings July 16, 2026 01:32

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread .claude/skills/sdk-functional-test-langfuse/scripts/inspect_env.py Fixed
JasonW404 added 10 commits July 16, 2026 09:34
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
…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
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.

3 participants