Owns conversation history and the tool-aware model loop.
| 17 | |
| 18 | |
| 19 | class QueryEngine: |
| 20 | """Owns conversation history and the tool-aware model loop.""" |
| 21 | |
| 22 | def __init__( |
| 23 | self, |
| 24 | *, |
| 25 | api_client: SupportsStreamingMessages, |
| 26 | tool_registry: ToolRegistry, |
| 27 | permission_checker: PermissionChecker, |
| 28 | cwd: str | Path, |
| 29 | model: str, |
| 30 | system_prompt: str, |
| 31 | max_tokens: int = 4096, |
| 32 | context_window_tokens: int | None = None, |
| 33 | auto_compact_threshold_tokens: int | None = None, |
| 34 | max_turns: int | None = 8, |
| 35 | permission_prompt: PermissionPrompt | None = None, |
| 36 | ask_user_prompt: AskUserPrompt | None = None, |
| 37 | hook_executor: HookExecutor | None = None, |
| 38 | tool_metadata: dict[str, object] | None = None, |
| 39 | ) -> None: |
| 40 | self._api_client = api_client |
| 41 | self._tool_registry = tool_registry |
| 42 | self._permission_checker = permission_checker |
| 43 | self._cwd = Path(cwd).resolve() |
| 44 | self._model = model |
| 45 | self._system_prompt = system_prompt |
| 46 | self._max_tokens = max_tokens |
| 47 | self._context_window_tokens = context_window_tokens |
| 48 | self._auto_compact_threshold_tokens = auto_compact_threshold_tokens |
| 49 | self._max_turns = max_turns |
| 50 | self._permission_prompt = permission_prompt |
| 51 | self._ask_user_prompt = ask_user_prompt |
| 52 | self._hook_executor = hook_executor |
| 53 | self._tool_metadata = tool_metadata or {} |
| 54 | self._messages: list[ConversationMessage] = [] |
| 55 | self._cost_tracker = CostTracker() |
| 56 | |
| 57 | @property |
| 58 | def messages(self) -> list[ConversationMessage]: |
| 59 | """Return the current conversation history.""" |
| 60 | return list(self._messages) |
| 61 | |
| 62 | @property |
| 63 | def max_turns(self) -> int | None: |
| 64 | """Return the maximum number of agentic turns per user input, if capped.""" |
| 65 | return self._max_turns |
| 66 | |
| 67 | @property |
| 68 | def api_client(self) -> SupportsStreamingMessages: |
| 69 | """Return the active API client.""" |
| 70 | return self._api_client |
| 71 | |
| 72 | @property |
| 73 | def model(self) -> str: |
| 74 | """Return the active model identifier.""" |
| 75 | return self._model |
| 76 |
no outgoing calls