predictor
zocrates.agents.coordinator.predictor ¶
Predictive next-prompt engine: suggests the user's next research prompt.
DEFAULT_PREDICTIVE_PROMPT_MODEL
module-attribute
¶
PREDICTOR_SYSTEM_PROMPT
module-attribute
¶
PREDICTOR_SYSTEM_PROMPT = '# Role and Objective\n\nYou are the Next-Move Predictor for Zocrates, an AI research assistant embedded inside Zotero.\n\nGiven the recent research turns: predict the single most valuable, actionable, and logical next prompt the user would send to advance their research.\n\n# Rules\n\n- Length: Strictly 5 to 15 words. Single line only.\n- Perspective: Direct user voice (an imperative command or query the user would type).\n - Good: "Search online literature for papers on Medusa speculative decoding"\n - Good: "Compare Medusa decoding heads against our library draft models"\n - Good: "Show experimental benchmarks comparing draft models on GSM8K"\n - Bad: "Would you like me to find more papers?" (Do NOT speak as the assistant)\n - Bad: "Can you explain this further?" (Too vague)\n- Actionability:\n - If the research response identified coverage gaps in the library, predict an online literature search filling those specific gaps.\n - If candidate papers were just imported or discovered, predict a comparison or methodological breakdown of those papers.\n - If a complex methodology was explained, predict an inquiry into empirical results, tradeoffs, or code implementations.\n- Suppression: If the conversation is purely conversational, a courtesy exchange ("Thanks!"), or has reached a natural resting point with no obvious next research move, output EXACTLY: null.\n'
_safe_set ¶
Safely set an attribute on an active OpenTelemetry span, no-oping on error or None.
Source code in zocrates/agents/coordinator/predictor.py
_start_predictor_span ¶
Return a context manager yielding an OpenTelemetry span, or None on fallback.
Source code in zocrates/agents/coordinator/predictor.py
_usage_count ¶
Read a token count from a litellm usage object or dict, defaulting to 0.
Source code in zocrates/agents/coordinator/predictor.py
calculate_event_cost ¶
calculate_event_cost(model_name, prompt_tokens, candidates_tokens, cached_tokens=0, zotero_data_dir=None)
Calculate the USD cost for a single model generation event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str | None
|
The identifier of the model used. |
required |
prompt_tokens
|
int
|
Total prompt token count (including cached tokens). |
required |
candidates_tokens
|
int
|
Completion token count (includes thoughts; not double-counted). |
required |
cached_tokens
|
int
|
Number of prompt tokens read from cache. |
0
|
zotero_data_dir
|
Path | str | None
|
Optional Zotero data directory for catalog discovery. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
USD cost as a float. |
Source code in zocrates/utils/cost_calculator.py
format_research_turn_history_context ¶
Format the last 2 research pipeline turns (User Query + Search Goal + Conclude Output).
Provides deep multi-turn continuity across library search and online discovery in an ultra-compact (<200 tokens) structured representation.
Source code in zocrates/agents/coordinator/predictor.py
parse_predicted_prompt ¶
Parse, sanitize, and validate the predicted prompt string.
Source code in zocrates/agents/coordinator/predictor.py
predict_next_user_prompt
async
¶
predict_next_user_prompt(research_history, model=DEFAULT_PREDICTIVE_PROMPT_MODEL, api_key=None, telemetry_out=None)
Execute a direct litellm.acompletion call to predict the next user prompt.
Returns None on empty context, suppression, timeout, or any provider error.
When telemetry_out is provided it is cleared and populated with the model,
latency, token usage, cost, status and suggestion of the call.
Source code in zocrates/agents/coordinator/predictor.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |