aid-runtime-python 0.1.39__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. aid_runtime/__init__.py +500 -0
  2. aid_runtime/agents/__init__.py +94 -0
  3. aid_runtime/agents/chat_model.py +351 -0
  4. aid_runtime/agents/deep_agents.py +600 -0
  5. aid_runtime/agents/engine.py +102 -0
  6. aid_runtime/agents/guardrails.py +519 -0
  7. aid_runtime/agents/ir.py +622 -0
  8. aid_runtime/agents/loop.py +1308 -0
  9. aid_runtime/agents/memory.py +241 -0
  10. aid_runtime/agents/policy.py +163 -0
  11. aid_runtime/agents/state.py +182 -0
  12. aid_runtime/cache.py +185 -0
  13. aid_runtime/concurrency.py +70 -0
  14. aid_runtime/control.py +329 -0
  15. aid_runtime/cost.py +168 -0
  16. aid_runtime/errors.py +337 -0
  17. aid_runtime/evals/__init__.py +72 -0
  18. aid_runtime/evals/dataset.py +77 -0
  19. aid_runtime/evals/gate.py +430 -0
  20. aid_runtime/evals/metrics.py +335 -0
  21. aid_runtime/evals/predicate.py +211 -0
  22. aid_runtime/evals/runner.py +224 -0
  23. aid_runtime/gateway.py +473 -0
  24. aid_runtime/pipeline.py +168 -0
  25. aid_runtime/prompts.py +185 -0
  26. aid_runtime/providers/__init__.py +20 -0
  27. aid_runtime/providers/base.py +57 -0
  28. aid_runtime/providers/fake.py +256 -0
  29. aid_runtime/providers/http.py +344 -0
  30. aid_runtime/py.typed +0 -0
  31. aid_runtime/retrieval/__init__.py +178 -0
  32. aid_runtime/retrieval/chunking.py +222 -0
  33. aid_runtime/retrieval/citations.py +131 -0
  34. aid_runtime/retrieval/connectors.py +131 -0
  35. aid_runtime/retrieval/embedding.py +293 -0
  36. aid_runtime/retrieval/gate.py +120 -0
  37. aid_runtime/retrieval/hybrid.py +164 -0
  38. aid_runtime/retrieval/metrics.py +213 -0
  39. aid_runtime/retrieval/pgvector.py +258 -0
  40. aid_runtime/retrieval/rerank.py +133 -0
  41. aid_runtime/retrieval/retriever.py +335 -0
  42. aid_runtime/retrieval/stores.py +161 -0
  43. aid_runtime/retrieval/types.py +433 -0
  44. aid_runtime/steps.py +284 -0
  45. aid_runtime/structured.py +150 -0
  46. aid_runtime/tools.py +271 -0
  47. aid_runtime/tracing.py +241 -0
  48. aid_runtime/types.py +332 -0
  49. aid_runtime_python-0.1.39.dist-info/METADATA +268 -0
  50. aid_runtime_python-0.1.39.dist-info/RECORD +52 -0
  51. aid_runtime_python-0.1.39.dist-info/WHEEL +5 -0
  52. aid_runtime_python-0.1.39.dist-info/top_level.txt +1 -0
@@ -0,0 +1,500 @@
1
+ """AID runtime for Python: the execution half of a generated application.
2
+
3
+ The AID framework generates an application from an IR that declares *what* the
4
+ app does. This package is what the generated code calls at runtime: pin a model,
5
+ run a prompt, call a tool, trace it, stay inside a budget, and prove that quality
6
+ did not regress.
7
+
8
+ Design boundaries worth stating up front, because they are deliberate:
9
+
10
+ * **Control flow is plain async Python.** There is no graph or orchestration
11
+ engine here. A generated app is ordinary code that is easy to read and to test.
12
+ * **Pydantic AI is used only for structured output.** No other responsibility is
13
+ delegated to it.
14
+ * **Streaming is SSE, and served end to end.** A model and its adapter that
15
+ advertise ``Capability.STREAMING`` are served by
16
+ :meth:`~aid_runtime.gateway.ModelGateway.stream`, which yields Server-Sent Event
17
+ ``data`` frames with the first delta before completion. Anything not advertising
18
+ the capability raises :class:`~aid_runtime.errors.CapabilityMismatchError`
19
+ instead of pretending to stream.
20
+ * **One HTTP provider adapter and one fake.** Breadth of vendor coverage is a
21
+ Phase 2 concern; a narrow, correct seam is worth more now than a wide shallow one.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ from aid_runtime.agents import (
27
+ AgentCheckpoint,
28
+ AgentDefinition,
29
+ AgentRuntime,
30
+ FileMemoryStore,
31
+ HumanApproval,
32
+ HumanDecision,
33
+ InProcessMemoryStore,
34
+ MemoryDefinition,
35
+ MemoryStore,
36
+ PendingApproval,
37
+ Principal,
38
+ RunResult,
39
+ RunStatus,
40
+ RuntimeSpec,
41
+ StepKind,
42
+ StepRecord,
43
+ ThreadMemory,
44
+ ToolSpec,
45
+ )
46
+ from aid_runtime.cache import CompletionCache, cache_key_for
47
+ from aid_runtime.concurrency import ConcurrencyLimiter
48
+ from aid_runtime.control import (
49
+ DEPTH_KEY,
50
+ INDEX_KEY,
51
+ ITEM_KEY,
52
+ LIMITER_KEY,
53
+ MAX_STEP_DEPTH,
54
+ PRINCIPAL_KEY,
55
+ REDUCED_KEY,
56
+ RESERVED_KEYS,
57
+ branch,
58
+ map_step,
59
+ parallel,
60
+ reduce_step,
61
+ )
62
+ from aid_runtime.cost import (
63
+ Budget,
64
+ CostLedger,
65
+ LedgerEntry,
66
+ SpendSummary,
67
+ estimate_cost_usd,
68
+ estimate_prompt_cost_usd,
69
+ )
70
+ from aid_runtime.errors import (
71
+ AgentBudgetDegradedError,
72
+ AgentHandoffUnsupportedError,
73
+ AgentTransferCycleError,
74
+ AidRuntimeError,
75
+ BudgetExceededError,
76
+ CapabilityMismatchError,
77
+ ConfigurationError,
78
+ DeepAgentsEngineError,
79
+ DeepAgentsMaxStepsError,
80
+ DeepAgentsUnavailableError,
81
+ DeepAgentsVersionMismatchError,
82
+ EvalError,
83
+ FeatureDeferredError,
84
+ GateConfigurationError,
85
+ GuardrailBlockedError,
86
+ PipelineError,
87
+ PolicyEvaluationError,
88
+ PromptNotFoundError,
89
+ PromptRenderError,
90
+ ProviderError,
91
+ ProviderResponseError,
92
+ StructuredOutputError,
93
+ ToolArgumentError,
94
+ ToolExecutionError,
95
+ ToolNotFoundError,
96
+ ToolPermissionError,
97
+ UnknownModelAliasError,
98
+ )
99
+ from aid_runtime.evals import (
100
+ BaselineGate,
101
+ CaseOutcome,
102
+ Dataset,
103
+ DatasetRun,
104
+ EvalBaseline,
105
+ EvalCase,
106
+ EvalRun,
107
+ ExactMatch,
108
+ GateResult,
109
+ GatewayRunner,
110
+ JsonSchemaValid,
111
+ JudgeVerdict,
112
+ LlmJudge,
113
+ Metric,
114
+ MetricBaseline,
115
+ MetricGateResult,
116
+ MetricResult,
117
+ MetricRun,
118
+ NormalizedContains,
119
+ Runner,
120
+ Threshold,
121
+ default_metrics,
122
+ evaluate_once,
123
+ gate_from_config,
124
+ gateway_judge,
125
+ metric_names,
126
+ normalize,
127
+ run_evaluation,
128
+ z_critical,
129
+ )
130
+ from aid_runtime.gateway import ModelGateway, estimate_usage
131
+ from aid_runtime.pipeline import (
132
+ STEPS_KEY,
133
+ Pipeline,
134
+ PipelineContext,
135
+ Step,
136
+ StepResult,
137
+ StopPipeline,
138
+ )
139
+ from aid_runtime.prompts import Example, PromptRegistry, PromptTemplate, RenderedPrompt
140
+ from aid_runtime.providers import (
141
+ DEFAULT_BASE_URL,
142
+ FakeProvider,
143
+ OpenAICompatibleProvider,
144
+ Provider,
145
+ ScriptedTurn,
146
+ )
147
+ from aid_runtime.retrieval import (
148
+ DEFAULT_CANDIDATE_FACTOR,
149
+ Chunk,
150
+ Chunker,
151
+ ChunkingSpec,
152
+ ChunkingStrategy,
153
+ Citation,
154
+ CitationGrounding,
155
+ CodeChunker,
156
+ Connector,
157
+ DistanceMetric,
158
+ Embedder,
159
+ EmbeddingBatch,
160
+ EmbeddingCostProfile,
161
+ EmbeddingSpec,
162
+ FakeDeterministicEmbedder,
163
+ FileConnector,
164
+ FixedChunker,
165
+ IndexSpec,
166
+ IngestReport,
167
+ InMemoryVectorStore,
168
+ LexicalReranker,
169
+ MeanReciprocalRank,
170
+ OpenAICompatibleEmbedder,
171
+ PgVectorStore,
172
+ PinnedEmbedding,
173
+ RankedId,
174
+ RecallAtK,
175
+ RecursiveChunker,
176
+ RefreshMode,
177
+ RefreshSpec,
178
+ Reranker,
179
+ RerankSpec,
180
+ RetrievalCase,
181
+ RetrievalGate,
182
+ RetrievalMetric,
183
+ RetrievalMetricSpec,
184
+ RetrievalResult,
185
+ RetrievedItem,
186
+ Retriever,
187
+ RetrieverBinding,
188
+ RetrieverSpec,
189
+ ScoredChunk,
190
+ SearchHit,
191
+ SourceDocument,
192
+ SourceKind,
193
+ SourceSpec,
194
+ StoreKind,
195
+ StoreRecord,
196
+ VectorStore,
197
+ VectorStoreSpec,
198
+ assemble_context,
199
+ binding_from_spec,
200
+ bm25_scores,
201
+ chunk_document,
202
+ chunk_id_for,
203
+ chunker_for,
204
+ cite,
205
+ create_store,
206
+ embedder_for,
207
+ estimate_tokens,
208
+ fuse,
209
+ lexical_ranking,
210
+ lexical_score,
211
+ open_connector,
212
+ pinned_embedding,
213
+ reranker_for,
214
+ resolve_uri,
215
+ retrieval_metrics,
216
+ rrf_score,
217
+ similarity,
218
+ tokenize,
219
+ )
220
+ from aid_runtime.steps import (
221
+ EMITTED_KEY,
222
+ RetrieverSeam,
223
+ emit_step,
224
+ generate_step,
225
+ resolve_source,
226
+ retrieve_step,
227
+ tool_step,
228
+ )
229
+ from aid_runtime.structured import (
230
+ build_agent,
231
+ format_problems,
232
+ parse_structured,
233
+ repair_prompt,
234
+ run_structured,
235
+ )
236
+ from aid_runtime.tools import Tool, ToolExecutor
237
+ from aid_runtime.tracing import (
238
+ ATTRIBUTES,
239
+ GEN_AI_OPERATION_CHAT,
240
+ agent_span,
241
+ aid_attributes,
242
+ get_tracer,
243
+ llm_span,
244
+ record_attributes,
245
+ record_cost,
246
+ record_exception,
247
+ record_hitl,
248
+ record_usage,
249
+ )
250
+ from aid_runtime.types import (
251
+ Capability,
252
+ CompletionRequest,
253
+ CompletionResponse,
254
+ CostProfile,
255
+ FinishReason,
256
+ GenerationResult,
257
+ Message,
258
+ ModelCacheConfig,
259
+ ModelSpec,
260
+ PinnedModel,
261
+ Role,
262
+ SemanticCacheConfig,
263
+ StreamChunk,
264
+ TokenUsage,
265
+ ToolCall,
266
+ ToolDefinition,
267
+ ToolResult,
268
+ )
269
+
270
+ #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
271
+ __version__ = "0.1.39"
272
+
273
+ __all__ = [
274
+ "ATTRIBUTES",
275
+ "DEFAULT_BASE_URL",
276
+ "DEFAULT_CANDIDATE_FACTOR",
277
+ "DEPTH_KEY",
278
+ "EMITTED_KEY",
279
+ "GEN_AI_OPERATION_CHAT",
280
+ "INDEX_KEY",
281
+ "ITEM_KEY",
282
+ "LIMITER_KEY",
283
+ "MAX_STEP_DEPTH",
284
+ "PRINCIPAL_KEY",
285
+ "REDUCED_KEY",
286
+ "RESERVED_KEYS",
287
+ "STEPS_KEY",
288
+ "AgentBudgetDegradedError",
289
+ "AgentCheckpoint",
290
+ "AgentDefinition",
291
+ "AgentHandoffUnsupportedError",
292
+ "AgentRuntime",
293
+ "AgentTransferCycleError",
294
+ "AidRuntimeError",
295
+ "BaselineGate",
296
+ "Budget",
297
+ "BudgetExceededError",
298
+ "Capability",
299
+ "CapabilityMismatchError",
300
+ "CaseOutcome",
301
+ "Chunk",
302
+ "Chunker",
303
+ "ChunkingSpec",
304
+ "ChunkingStrategy",
305
+ "Citation",
306
+ "CitationGrounding",
307
+ "CodeChunker",
308
+ "CompletionCache",
309
+ "CompletionRequest",
310
+ "CompletionResponse",
311
+ "ConcurrencyLimiter",
312
+ "ConfigurationError",
313
+ "Connector",
314
+ "CostLedger",
315
+ "CostProfile",
316
+ "Dataset",
317
+ "DatasetRun",
318
+ "DeepAgentsEngineError",
319
+ "DeepAgentsMaxStepsError",
320
+ "DeepAgentsUnavailableError",
321
+ "DeepAgentsVersionMismatchError",
322
+ "DistanceMetric",
323
+ "Embedder",
324
+ "EmbeddingBatch",
325
+ "EmbeddingCostProfile",
326
+ "EmbeddingSpec",
327
+ "EvalBaseline",
328
+ "EvalCase",
329
+ "EvalError",
330
+ "EvalRun",
331
+ "ExactMatch",
332
+ "Example",
333
+ "FakeDeterministicEmbedder",
334
+ "FakeProvider",
335
+ "FeatureDeferredError",
336
+ "FileConnector",
337
+ "FileMemoryStore",
338
+ "FinishReason",
339
+ "FixedChunker",
340
+ "GateConfigurationError",
341
+ "GateResult",
342
+ "GatewayRunner",
343
+ "GenerationResult",
344
+ "GuardrailBlockedError",
345
+ "HumanApproval",
346
+ "HumanDecision",
347
+ "InMemoryVectorStore",
348
+ "InProcessMemoryStore",
349
+ "IndexSpec",
350
+ "IngestReport",
351
+ "JsonSchemaValid",
352
+ "JudgeVerdict",
353
+ "LedgerEntry",
354
+ "LexicalReranker",
355
+ "LlmJudge",
356
+ "MeanReciprocalRank",
357
+ "MemoryDefinition",
358
+ "MemoryStore",
359
+ "Message",
360
+ "Metric",
361
+ "MetricBaseline",
362
+ "MetricGateResult",
363
+ "MetricResult",
364
+ "MetricRun",
365
+ "ModelCacheConfig",
366
+ "ModelGateway",
367
+ "ModelSpec",
368
+ "NormalizedContains",
369
+ "OpenAICompatibleEmbedder",
370
+ "OpenAICompatibleProvider",
371
+ "PendingApproval",
372
+ "PgVectorStore",
373
+ "PinnedEmbedding",
374
+ "PinnedModel",
375
+ "Pipeline",
376
+ "PipelineContext",
377
+ "PipelineError",
378
+ "PolicyEvaluationError",
379
+ "Principal",
380
+ "PromptNotFoundError",
381
+ "PromptRegistry",
382
+ "PromptRenderError",
383
+ "PromptTemplate",
384
+ "Provider",
385
+ "ProviderError",
386
+ "ProviderResponseError",
387
+ "RankedId",
388
+ "RecallAtK",
389
+ "RecursiveChunker",
390
+ "RefreshMode",
391
+ "RefreshSpec",
392
+ "RenderedPrompt",
393
+ "RerankSpec",
394
+ "Reranker",
395
+ "RetrievalCase",
396
+ "RetrievalGate",
397
+ "RetrievalMetric",
398
+ "RetrievalMetricSpec",
399
+ "RetrievalResult",
400
+ "RetrievedItem",
401
+ "Retriever",
402
+ "RetrieverBinding",
403
+ "RetrieverSeam",
404
+ "RetrieverSpec",
405
+ "Role",
406
+ "RunResult",
407
+ "RunStatus",
408
+ "Runner",
409
+ "RuntimeSpec",
410
+ "ScoredChunk",
411
+ "ScriptedTurn",
412
+ "SearchHit",
413
+ "SemanticCacheConfig",
414
+ "SourceDocument",
415
+ "SourceKind",
416
+ "SourceSpec",
417
+ "SpendSummary",
418
+ "Step",
419
+ "StepKind",
420
+ "StepRecord",
421
+ "StepResult",
422
+ "StopPipeline",
423
+ "StoreKind",
424
+ "StoreRecord",
425
+ "StreamChunk",
426
+ "StructuredOutputError",
427
+ "ThreadMemory",
428
+ "Threshold",
429
+ "TokenUsage",
430
+ "Tool",
431
+ "ToolArgumentError",
432
+ "ToolCall",
433
+ "ToolDefinition",
434
+ "ToolExecutionError",
435
+ "ToolExecutor",
436
+ "ToolNotFoundError",
437
+ "ToolPermissionError",
438
+ "ToolResult",
439
+ "ToolSpec",
440
+ "UnknownModelAliasError",
441
+ "VectorStore",
442
+ "VectorStoreSpec",
443
+ "__version__",
444
+ "agent_span",
445
+ "aid_attributes",
446
+ "assemble_context",
447
+ "binding_from_spec",
448
+ "bm25_scores",
449
+ "branch",
450
+ "build_agent",
451
+ "cache_key_for",
452
+ "chunk_document",
453
+ "chunk_id_for",
454
+ "chunker_for",
455
+ "cite",
456
+ "create_store",
457
+ "default_metrics",
458
+ "embedder_for",
459
+ "emit_step",
460
+ "estimate_cost_usd",
461
+ "estimate_prompt_cost_usd",
462
+ "estimate_tokens",
463
+ "estimate_usage",
464
+ "evaluate_once",
465
+ "format_problems",
466
+ "fuse",
467
+ "gate_from_config",
468
+ "gateway_judge",
469
+ "generate_step",
470
+ "get_tracer",
471
+ "lexical_ranking",
472
+ "lexical_score",
473
+ "llm_span",
474
+ "map_step",
475
+ "metric_names",
476
+ "normalize",
477
+ "open_connector",
478
+ "parallel",
479
+ "parse_structured",
480
+ "pinned_embedding",
481
+ "record_attributes",
482
+ "record_cost",
483
+ "record_exception",
484
+ "record_hitl",
485
+ "record_usage",
486
+ "reduce_step",
487
+ "repair_prompt",
488
+ "reranker_for",
489
+ "resolve_source",
490
+ "resolve_uri",
491
+ "retrieval_metrics",
492
+ "retrieve_step",
493
+ "rrf_score",
494
+ "run_evaluation",
495
+ "run_structured",
496
+ "similarity",
497
+ "tokenize",
498
+ "tool_step",
499
+ "z_critical",
500
+ ]
@@ -0,0 +1,94 @@
1
+ """The native agent runtime: a loop, control transfer and delegation, budgets, HITL.
2
+
3
+ The entry point is :class:`AgentRuntime`. Build it with
4
+ :meth:`AgentRuntime.from_ir` from an emitted IR document and call
5
+ :meth:`AgentRuntime.run`; a run that stops for a person returns a
6
+ :class:`RunResult` whose ``checkpoint`` is what :meth:`AgentRuntime.resume` needs.
7
+
8
+ Naming, because the IR's two control edges are easy to conflate:
9
+
10
+ * ``handoffs`` -> :meth:`AgentRuntime._transfer`. Control **moves**; the target
11
+ produces the final answer and the caller does not resume.
12
+ * ``delegates`` -> :meth:`AgentRuntime._delegate`. Control is **lent**; the
13
+ delegate returns one observation and the caller produces the final answer.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from aid_runtime.agents.guardrails import (
19
+ DETECTORS,
20
+ GUARDRAIL_ACTIONS,
21
+ GUARDRAIL_STAGES,
22
+ Detection,
23
+ GuardrailEngine,
24
+ GuardrailEscalation,
25
+ GuardrailRecord,
26
+ GuardrailVerdict,
27
+ detect,
28
+ )
29
+ from aid_runtime.agents.ir import (
30
+ AgentDefinition,
31
+ GuardrailDefinition,
32
+ HumanApproval,
33
+ MemoryDefinition,
34
+ RuntimeSpec,
35
+ ToolSpec,
36
+ )
37
+ from aid_runtime.agents.loop import AgentRuntime
38
+ from aid_runtime.agents.memory import (
39
+ IMPLEMENTED_MEMORY_KINDS,
40
+ MEMORY_SCOPES,
41
+ FileMemoryStore,
42
+ InProcessMemoryStore,
43
+ MemoryStore,
44
+ ThreadMemory,
45
+ check_memory_supported,
46
+ render_context,
47
+ )
48
+ from aid_runtime.agents.policy import Principal, evaluate_policy, policy_source
49
+ from aid_runtime.agents.state import (
50
+ AgentCheckpoint,
51
+ HumanDecision,
52
+ PendingApproval,
53
+ RunResult,
54
+ RunStatus,
55
+ StepKind,
56
+ StepRecord,
57
+ )
58
+
59
+ __all__ = [
60
+ "DETECTORS",
61
+ "GUARDRAIL_ACTIONS",
62
+ "GUARDRAIL_STAGES",
63
+ "IMPLEMENTED_MEMORY_KINDS",
64
+ "MEMORY_SCOPES",
65
+ "AgentCheckpoint",
66
+ "AgentDefinition",
67
+ "AgentRuntime",
68
+ "Detection",
69
+ "FileMemoryStore",
70
+ "GuardrailDefinition",
71
+ "GuardrailEngine",
72
+ "GuardrailEscalation",
73
+ "GuardrailRecord",
74
+ "GuardrailVerdict",
75
+ "HumanApproval",
76
+ "HumanDecision",
77
+ "InProcessMemoryStore",
78
+ "MemoryDefinition",
79
+ "MemoryStore",
80
+ "PendingApproval",
81
+ "Principal",
82
+ "RunResult",
83
+ "RunStatus",
84
+ "RuntimeSpec",
85
+ "StepKind",
86
+ "StepRecord",
87
+ "ThreadMemory",
88
+ "ToolSpec",
89
+ "check_memory_supported",
90
+ "detect",
91
+ "evaluate_policy",
92
+ "policy_source",
93
+ "render_context",
94
+ ]