prompture 0.0.35__py3-none-any.whl → 0.0.40.dev1__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.
- prompture/__init__.py +132 -3
- prompture/_version.py +2 -2
- prompture/agent.py +924 -0
- prompture/agent_types.py +156 -0
- prompture/async_agent.py +880 -0
- prompture/async_conversation.py +208 -17
- prompture/async_core.py +16 -0
- prompture/async_driver.py +63 -0
- prompture/async_groups.py +551 -0
- prompture/conversation.py +222 -18
- prompture/core.py +46 -12
- prompture/cost_mixin.py +37 -0
- prompture/discovery.py +132 -44
- prompture/driver.py +77 -0
- prompture/drivers/__init__.py +5 -1
- prompture/drivers/async_azure_driver.py +11 -5
- prompture/drivers/async_claude_driver.py +184 -9
- prompture/drivers/async_google_driver.py +222 -28
- prompture/drivers/async_grok_driver.py +11 -5
- prompture/drivers/async_groq_driver.py +11 -5
- prompture/drivers/async_lmstudio_driver.py +74 -5
- prompture/drivers/async_ollama_driver.py +13 -3
- prompture/drivers/async_openai_driver.py +162 -5
- prompture/drivers/async_openrouter_driver.py +11 -5
- prompture/drivers/async_registry.py +5 -1
- prompture/drivers/azure_driver.py +10 -4
- prompture/drivers/claude_driver.py +17 -1
- prompture/drivers/google_driver.py +227 -33
- prompture/drivers/grok_driver.py +11 -5
- prompture/drivers/groq_driver.py +11 -5
- prompture/drivers/lmstudio_driver.py +73 -8
- prompture/drivers/ollama_driver.py +16 -5
- prompture/drivers/openai_driver.py +26 -11
- prompture/drivers/openrouter_driver.py +11 -5
- prompture/drivers/vision_helpers.py +153 -0
- prompture/group_types.py +147 -0
- prompture/groups.py +530 -0
- prompture/image.py +180 -0
- prompture/ledger.py +252 -0
- prompture/model_rates.py +112 -2
- prompture/persistence.py +254 -0
- prompture/persona.py +482 -0
- prompture/serialization.py +218 -0
- prompture/settings.py +1 -0
- prompture-0.0.40.dev1.dist-info/METADATA +369 -0
- prompture-0.0.40.dev1.dist-info/RECORD +78 -0
- prompture-0.0.35.dist-info/METADATA +0 -464
- prompture-0.0.35.dist-info/RECORD +0 -66
- {prompture-0.0.35.dist-info → prompture-0.0.40.dev1.dist-info}/WHEEL +0 -0
- {prompture-0.0.35.dist-info → prompture-0.0.40.dev1.dist-info}/entry_points.txt +0 -0
- {prompture-0.0.35.dist-info → prompture-0.0.40.dev1.dist-info}/licenses/LICENSE +0 -0
- {prompture-0.0.35.dist-info → prompture-0.0.40.dev1.dist-info}/top_level.txt +0 -0
prompture/agent_types.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Shared types for the Agent framework.
|
|
2
|
+
|
|
3
|
+
Defines enums, dataclasses, and exceptions used by :class:`~prompture.agent.Agent`.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import enum
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from typing import Any, Generic, TypeVar
|
|
12
|
+
|
|
13
|
+
DepsType = TypeVar("DepsType")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AgentState(enum.Enum):
|
|
17
|
+
"""Lifecycle state of an Agent run."""
|
|
18
|
+
|
|
19
|
+
idle = "idle"
|
|
20
|
+
running = "running"
|
|
21
|
+
stopped = "stopped"
|
|
22
|
+
errored = "errored"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class StepType(enum.Enum):
|
|
26
|
+
"""Classification for individual steps within an Agent run."""
|
|
27
|
+
|
|
28
|
+
think = "think"
|
|
29
|
+
tool_call = "tool_call"
|
|
30
|
+
tool_result = "tool_result"
|
|
31
|
+
output = "output"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ModelRetry(Exception):
|
|
35
|
+
"""Raised to feed an error message back to the LLM for retry.
|
|
36
|
+
|
|
37
|
+
Tools raise this to return an error string to the LLM.
|
|
38
|
+
Output guardrails raise this to re-prompt the LLM.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, message: str) -> None:
|
|
42
|
+
self.message = message
|
|
43
|
+
super().__init__(message)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class GuardrailError(Exception):
|
|
47
|
+
"""Raised when an input guardrail rejects the prompt entirely."""
|
|
48
|
+
|
|
49
|
+
def __init__(self, message: str) -> None:
|
|
50
|
+
self.message = message
|
|
51
|
+
super().__init__(message)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class RunContext(Generic[DepsType]):
|
|
56
|
+
"""Dependency-injection context available to tools and guardrails.
|
|
57
|
+
|
|
58
|
+
Built at the start of each :meth:`Agent.run` invocation and passed
|
|
59
|
+
automatically to tools whose first parameter is annotated as
|
|
60
|
+
``RunContext``.
|
|
61
|
+
|
|
62
|
+
Attributes:
|
|
63
|
+
deps: User-supplied dependencies (database handles, API clients, etc.).
|
|
64
|
+
model: The model string used for this run.
|
|
65
|
+
usage: Snapshot of :class:`UsageSession.summary()` at context-build time.
|
|
66
|
+
messages: Copy of conversation history at context-build time.
|
|
67
|
+
iteration: Current iteration index (0 at the start of the run).
|
|
68
|
+
prompt: The original user prompt for this run.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
deps: DepsType
|
|
72
|
+
model: str
|
|
73
|
+
usage: dict[str, Any] = field(default_factory=dict)
|
|
74
|
+
messages: list[dict[str, Any]] = field(default_factory=list)
|
|
75
|
+
iteration: int = 0
|
|
76
|
+
prompt: str = ""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass
|
|
80
|
+
class AgentCallbacks:
|
|
81
|
+
"""Agent-level observability callbacks.
|
|
82
|
+
|
|
83
|
+
Fired at the logical agent layer (steps, tool invocations, output),
|
|
84
|
+
separate from :class:`~prompture.callbacks.DriverCallbacks` which
|
|
85
|
+
fires at the HTTP/driver layer.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
on_step: Callable[[AgentStep], None] | None = None
|
|
89
|
+
on_tool_start: Callable[[str, dict[str, Any]], None] | None = None
|
|
90
|
+
on_tool_end: Callable[[str, Any], None] | None = None
|
|
91
|
+
on_iteration: Callable[[int], None] | None = None
|
|
92
|
+
on_output: Callable[[AgentResult], None] | None = None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass
|
|
96
|
+
class AgentStep:
|
|
97
|
+
"""A single step recorded during an Agent run."""
|
|
98
|
+
|
|
99
|
+
step_type: StepType
|
|
100
|
+
timestamp: float
|
|
101
|
+
content: str = ""
|
|
102
|
+
tool_name: str | None = None
|
|
103
|
+
tool_args: dict[str, Any] | None = None
|
|
104
|
+
tool_result: Any = None
|
|
105
|
+
duration_ms: float = 0.0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@dataclass
|
|
109
|
+
class AgentResult:
|
|
110
|
+
"""The outcome of an :meth:`Agent.run` invocation.
|
|
111
|
+
|
|
112
|
+
Attributes:
|
|
113
|
+
output: Parsed Pydantic model instance (if ``output_type`` is set)
|
|
114
|
+
or the raw text response.
|
|
115
|
+
output_text: The raw text from the final LLM response.
|
|
116
|
+
messages: Full conversation message history from the run.
|
|
117
|
+
usage: Accumulated token/cost totals.
|
|
118
|
+
steps: Ordered list of :class:`AgentStep` recorded during the run.
|
|
119
|
+
all_tool_calls: Flat list of tool-call dicts extracted from messages.
|
|
120
|
+
state: Final :class:`AgentState` after the run completes.
|
|
121
|
+
run_usage: Per-run :class:`UsageSession` summary dict.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
output: Any
|
|
125
|
+
output_text: str
|
|
126
|
+
messages: list[dict[str, Any]]
|
|
127
|
+
usage: dict[str, Any]
|
|
128
|
+
steps: list[AgentStep] = field(default_factory=list)
|
|
129
|
+
all_tool_calls: list[dict[str, Any]] = field(default_factory=list)
|
|
130
|
+
state: AgentState = AgentState.idle
|
|
131
|
+
run_usage: dict[str, Any] = field(default_factory=dict)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class StreamEventType(str, enum.Enum):
|
|
135
|
+
"""Classification for events emitted during streaming agent execution."""
|
|
136
|
+
|
|
137
|
+
text_delta = "text_delta"
|
|
138
|
+
tool_call = "tool_call"
|
|
139
|
+
tool_result = "tool_result"
|
|
140
|
+
output = "output"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@dataclass
|
|
144
|
+
class StreamEvent:
|
|
145
|
+
"""A single event emitted during a streaming agent run.
|
|
146
|
+
|
|
147
|
+
Attributes:
|
|
148
|
+
event_type: The kind of event.
|
|
149
|
+
data: Payload — ``str`` for text_delta, ``dict`` for tool_call/result,
|
|
150
|
+
:class:`AgentResult` for output.
|
|
151
|
+
step: Optional associated :class:`AgentStep`.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
event_type: StreamEventType
|
|
155
|
+
data: Any
|
|
156
|
+
step: AgentStep | None = None
|