| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- """Knowledge extraction and injection configuration.
- This value object belongs to the runner configuration layer. Keeping it out
- of the builtin HTTP tool module prevents core configuration imports from
- triggering builtin tool registration.
- """
- from __future__ import annotations
- import subprocess
- from dataclasses import dataclass
- from typing import Dict, List, Optional
- from agent.core.prompts import COMPLETION_REFLECT_PROMPT, build_reflect_prompt
- @dataclass
- class KnowledgeConfig:
- """Configure knowledge extraction, review, and prompt injection."""
- enable_extraction: bool = True
- reflect_prompt: str = ""
- enable_completion_extraction: bool = True
- completion_reflect_prompt: str = ""
- reflect_auto_commit: bool = False
- enable_injection: bool = True
- owner: str = ""
- default_tags: Optional[Dict[str, str]] = None
- default_scopes: Optional[List[str]] = None
- default_search_types: Optional[List[str]] = None
- default_search_owner: str = ""
- def get_reflect_prompt(self) -> str:
- """Return the configured compression-reflection prompt."""
- return self.reflect_prompt or build_reflect_prompt()
- def get_completion_reflect_prompt(self) -> str:
- """Return the configured completion-reflection prompt."""
- return self.completion_reflect_prompt or COMPLETION_REFLECT_PROMPT
- @property
- def resolved_owner(self) -> str:
- """Resolve owner from explicit config, Git identity, then ``agent``."""
- if self.owner:
- return self.owner
- try:
- result = subprocess.run(
- ["git", "config", "user.email"],
- capture_output=True,
- text=True,
- timeout=2,
- )
- if result.returncode == 0 and result.stdout.strip():
- return result.stdout.strip()
- except (OSError, subprocess.SubprocessError):
- pass
- return "agent"
- def get_owner(self, agent_id: str = "agent") -> str:
- """Return the resolved owner, namespaced for non-default agents."""
- owner = self.resolved_owner
- if owner == "agent" and agent_id != "agent":
- return f"agent:{agent_id}"
- return owner
- __all__ = ["KnowledgeConfig"]
|