1"""Package-internal protocols for speculative execution."""
2
3from __future__ import annotations
4
5from typing import Protocol, runtime_checkable
6
7from lexigram.contracts import (
8 ToolProtocol,
9)
10from lexigram.contracts.ai.llm import ChatMessage
11
12
13@runtime_checkable
14class ToolCallPredictorProtocol(Protocol):
15 """Predicts which tools the LLM is likely to call for a given query.
16
17 Package-internal protocol. Not in contracts because it is only consumed
18 by SpeculativeToolPreFetcher within lexigram-ai-agents.
19 """
20
21 def predict(
22 self,
23 query: str,
24 available_tools: list[ToolProtocol],
25 recent_history: list[ChatMessage] | None = None,
26 ) -> list[ToolProtocol]:
27 """Return tools ranked by likelihood of being called.
28
29 Args:
30 query: The current user query.
31 available_tools: All tools registered in the agent.
32 recent_history: Recent conversation turns for context.
33
34 Returns:
35 Tools sorted by predicted likelihood, most likely first.
36 """
37 ...