Skip to content

feat: Add model context system for improved project awareness#375

Merged
edenreich merged 2 commits intomainfrom
feat/model-context-system
Jan 24, 2026
Merged

feat: Add model context system for improved project awareness#375
edenreich merged 2 commits intomainfrom
feat/model-context-system

Conversation

@edenreich
Copy link
Contributor

Adds automatic git repository and working directory context to the AI agent. The system provides repository name, branch info, recent commits, and working directory path to reduce confusion and improve accuracy. Includes caching for performance and configurable refresh intervals.

What changed

  • Added context enrichment system that automatically injects git repository info (name, branch, commits) and working directory into the agent's system prompt
  • Enabled A2A (Agent-to-Agent) functionality
  • Implemented caching for performance with configurable refresh intervals
  • Updated documentation in CLAUDE.md
  • Added configuration options and default values
  • Added test cases for the new git utilities

Why changed

To reduce model confusion about repository identity and improve accuracy by providing project context. Previously, models were often confused about repository names ("inference-gateway" vs "inference-gateway/cli" vs "inference-gateway/infer") and had no awareness of current branch or git state.

Configuration

Enabled by default with:

  • git_context_enabled: true
  • working_dir_enabled: true
  • git_context_refresh_turns: 10 (configurable refresh rate)

Performance

  • First prompt: +50-100ms (git command execution)
  • Subsequent prompts: <1ms (cached)
  • Token overhead: ~100-300 tokens (depends on git history)
  • Git refresh: Every 10 turns by default (configurable)

Benefits

Before:

  • Model confused about repository name
  • No awareness of current branch or git state
  • Unclear about working directory

After:

  • Model knows exact repository: inference-gateway/cli
  • Aware of current branch and recent commits
  • Understands working directory context
  • Reduced need for clarifying questions

Implementation Details

  • Location: internal/services/agent_utils.go
  • Context builders: buildGitContextInfo(), buildWorkingDirectoryInfo()
  • Git helpers: isGitRepository(), getGitRepositoryName(), getGitBranch(), getGitMainBranch(), getRecentCommits()
  • Caching: Thread-safe caching via sync.RWMutex in AgentServiceImpl
  • Error handling: All git operations fail gracefully (log debug, return empty string)

@edenreich edenreich merged commit 1afb26b into main Jan 24, 2026
5 checks passed
@edenreich edenreich deleted the feat/model-context-system branch January 24, 2026 13:15
ig-semantic-release-bot bot pushed a commit that referenced this pull request Jan 24, 2026
## [0.99.0](v0.98.0...v0.99.0) (2026-01-24)

### 🚀 Features

* Add model context system for improved project awareness ([#375](#375)) ([1afb26b](1afb26b))

### 🐛 Bug Fixes

* Skip migrations for JSONL storage in infer init ([#376](#376)) ([3793345](3793345)), closes [#372](#372)

### ♻️ Code Refactoring

* Improve the testability of conversation optimizer ([#374](#374)) ([4c7c428](4c7c428))
@ig-semantic-release-bot
Copy link

🎉 This PR is included in version 0.99.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant