agentrun-sdk 0.1.2__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.
Potentially problematic release.
This version of agentrun-sdk might be problematic. Click here for more details.
- agentrun_operation_sdk/cli/__init__.py +1 -0
- agentrun_operation_sdk/cli/cli.py +19 -0
- agentrun_operation_sdk/cli/common.py +21 -0
- agentrun_operation_sdk/cli/runtime/__init__.py +1 -0
- agentrun_operation_sdk/cli/runtime/commands.py +203 -0
- agentrun_operation_sdk/client/client.py +75 -0
- agentrun_operation_sdk/operations/runtime/__init__.py +8 -0
- agentrun_operation_sdk/operations/runtime/configure.py +101 -0
- agentrun_operation_sdk/operations/runtime/launch.py +82 -0
- agentrun_operation_sdk/operations/runtime/models.py +31 -0
- agentrun_operation_sdk/services/runtime.py +152 -0
- agentrun_operation_sdk/utils/logging_config.py +72 -0
- agentrun_operation_sdk/utils/runtime/config.py +94 -0
- agentrun_operation_sdk/utils/runtime/container.py +280 -0
- agentrun_operation_sdk/utils/runtime/entrypoint.py +203 -0
- agentrun_operation_sdk/utils/runtime/schema.py +56 -0
- agentrun_sdk/__init__.py +7 -0
- agentrun_sdk/agent/__init__.py +25 -0
- agentrun_sdk/agent/agent.py +696 -0
- agentrun_sdk/agent/agent_result.py +46 -0
- agentrun_sdk/agent/conversation_manager/__init__.py +26 -0
- agentrun_sdk/agent/conversation_manager/conversation_manager.py +88 -0
- agentrun_sdk/agent/conversation_manager/null_conversation_manager.py +46 -0
- agentrun_sdk/agent/conversation_manager/sliding_window_conversation_manager.py +179 -0
- agentrun_sdk/agent/conversation_manager/summarizing_conversation_manager.py +252 -0
- agentrun_sdk/agent/state.py +97 -0
- agentrun_sdk/event_loop/__init__.py +9 -0
- agentrun_sdk/event_loop/event_loop.py +499 -0
- agentrun_sdk/event_loop/streaming.py +319 -0
- agentrun_sdk/experimental/__init__.py +4 -0
- agentrun_sdk/experimental/hooks/__init__.py +15 -0
- agentrun_sdk/experimental/hooks/events.py +123 -0
- agentrun_sdk/handlers/__init__.py +10 -0
- agentrun_sdk/handlers/callback_handler.py +70 -0
- agentrun_sdk/hooks/__init__.py +49 -0
- agentrun_sdk/hooks/events.py +80 -0
- agentrun_sdk/hooks/registry.py +247 -0
- agentrun_sdk/models/__init__.py +10 -0
- agentrun_sdk/models/anthropic.py +432 -0
- agentrun_sdk/models/bedrock.py +649 -0
- agentrun_sdk/models/litellm.py +225 -0
- agentrun_sdk/models/llamaapi.py +438 -0
- agentrun_sdk/models/mistral.py +539 -0
- agentrun_sdk/models/model.py +95 -0
- agentrun_sdk/models/ollama.py +357 -0
- agentrun_sdk/models/openai.py +436 -0
- agentrun_sdk/models/sagemaker.py +598 -0
- agentrun_sdk/models/writer.py +449 -0
- agentrun_sdk/multiagent/__init__.py +22 -0
- agentrun_sdk/multiagent/a2a/__init__.py +15 -0
- agentrun_sdk/multiagent/a2a/executor.py +148 -0
- agentrun_sdk/multiagent/a2a/server.py +252 -0
- agentrun_sdk/multiagent/base.py +92 -0
- agentrun_sdk/multiagent/graph.py +555 -0
- agentrun_sdk/multiagent/swarm.py +656 -0
- agentrun_sdk/py.typed +1 -0
- agentrun_sdk/session/__init__.py +18 -0
- agentrun_sdk/session/file_session_manager.py +216 -0
- agentrun_sdk/session/repository_session_manager.py +152 -0
- agentrun_sdk/session/s3_session_manager.py +272 -0
- agentrun_sdk/session/session_manager.py +73 -0
- agentrun_sdk/session/session_repository.py +51 -0
- agentrun_sdk/telemetry/__init__.py +21 -0
- agentrun_sdk/telemetry/config.py +194 -0
- agentrun_sdk/telemetry/metrics.py +476 -0
- agentrun_sdk/telemetry/metrics_constants.py +15 -0
- agentrun_sdk/telemetry/tracer.py +563 -0
- agentrun_sdk/tools/__init__.py +17 -0
- agentrun_sdk/tools/decorator.py +569 -0
- agentrun_sdk/tools/executor.py +137 -0
- agentrun_sdk/tools/loader.py +152 -0
- agentrun_sdk/tools/mcp/__init__.py +13 -0
- agentrun_sdk/tools/mcp/mcp_agent_tool.py +99 -0
- agentrun_sdk/tools/mcp/mcp_client.py +423 -0
- agentrun_sdk/tools/mcp/mcp_instrumentation.py +322 -0
- agentrun_sdk/tools/mcp/mcp_types.py +63 -0
- agentrun_sdk/tools/registry.py +607 -0
- agentrun_sdk/tools/structured_output.py +421 -0
- agentrun_sdk/tools/tools.py +217 -0
- agentrun_sdk/tools/watcher.py +136 -0
- agentrun_sdk/types/__init__.py +5 -0
- agentrun_sdk/types/collections.py +23 -0
- agentrun_sdk/types/content.py +188 -0
- agentrun_sdk/types/event_loop.py +48 -0
- agentrun_sdk/types/exceptions.py +81 -0
- agentrun_sdk/types/guardrails.py +254 -0
- agentrun_sdk/types/media.py +89 -0
- agentrun_sdk/types/session.py +152 -0
- agentrun_sdk/types/streaming.py +201 -0
- agentrun_sdk/types/tools.py +258 -0
- agentrun_sdk/types/traces.py +5 -0
- agentrun_sdk-0.1.2.dist-info/METADATA +51 -0
- agentrun_sdk-0.1.2.dist-info/RECORD +115 -0
- agentrun_sdk-0.1.2.dist-info/WHEEL +5 -0
- agentrun_sdk-0.1.2.dist-info/entry_points.txt +2 -0
- agentrun_sdk-0.1.2.dist-info/top_level.txt +3 -0
- agentrun_wrapper/__init__.py +11 -0
- agentrun_wrapper/_utils/__init__.py +6 -0
- agentrun_wrapper/_utils/endpoints.py +16 -0
- agentrun_wrapper/identity/__init__.py +5 -0
- agentrun_wrapper/identity/auth.py +211 -0
- agentrun_wrapper/memory/__init__.py +6 -0
- agentrun_wrapper/memory/client.py +1697 -0
- agentrun_wrapper/memory/constants.py +103 -0
- agentrun_wrapper/memory/controlplane.py +626 -0
- agentrun_wrapper/py.typed +1 -0
- agentrun_wrapper/runtime/__init__.py +13 -0
- agentrun_wrapper/runtime/app.py +473 -0
- agentrun_wrapper/runtime/context.py +34 -0
- agentrun_wrapper/runtime/models.py +25 -0
- agentrun_wrapper/services/__init__.py +1 -0
- agentrun_wrapper/services/identity.py +192 -0
- agentrun_wrapper/tools/__init__.py +6 -0
- agentrun_wrapper/tools/browser_client.py +325 -0
- agentrun_wrapper/tools/code_interpreter_client.py +186 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Tool watcher for hot reloading tools during development.
|
|
2
|
+
|
|
3
|
+
This module provides functionality to watch tool directories for changes and automatically reload tools when they are
|
|
4
|
+
modified.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Dict, Set
|
|
10
|
+
|
|
11
|
+
from watchdog.events import FileSystemEventHandler
|
|
12
|
+
from watchdog.observers import Observer
|
|
13
|
+
|
|
14
|
+
from .registry import ToolRegistry
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ToolWatcher:
|
|
20
|
+
"""Watches tool directories for changes and reloads tools when they are modified."""
|
|
21
|
+
|
|
22
|
+
# This class uses class variables for the observer and handlers because watchdog allows only one Observer instance
|
|
23
|
+
# per directory. Using class variables ensures that all ToolWatcher instances share a single Observer, with the
|
|
24
|
+
# MasterChangeHandler routing file system events to the appropriate individual handlers for each registry. This
|
|
25
|
+
# design pattern avoids conflicts when multiple tool registries are watching the same directories.
|
|
26
|
+
|
|
27
|
+
_shared_observer = None
|
|
28
|
+
_watched_dirs: Set[str] = set()
|
|
29
|
+
_observer_started = False
|
|
30
|
+
_registry_handlers: Dict[str, Dict[int, "ToolWatcher.ToolChangeHandler"]] = {}
|
|
31
|
+
|
|
32
|
+
def __init__(self, tool_registry: ToolRegistry) -> None:
|
|
33
|
+
"""Initialize a tool watcher for the given tool registry.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
tool_registry: The tool registry to report changes.
|
|
37
|
+
"""
|
|
38
|
+
self.tool_registry = tool_registry
|
|
39
|
+
self.start()
|
|
40
|
+
|
|
41
|
+
class ToolChangeHandler(FileSystemEventHandler):
|
|
42
|
+
"""Handler for tool file changes."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, tool_registry: ToolRegistry) -> None:
|
|
45
|
+
"""Initialize a tool change handler.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
tool_registry: The tool registry to update when tools change.
|
|
49
|
+
"""
|
|
50
|
+
self.tool_registry = tool_registry
|
|
51
|
+
|
|
52
|
+
def on_modified(self, event: Any) -> None:
|
|
53
|
+
"""Reload tool if file modification detected.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
event: The file system event that triggered this handler.
|
|
57
|
+
"""
|
|
58
|
+
if event.src_path.endswith(".py"):
|
|
59
|
+
tool_path = Path(event.src_path)
|
|
60
|
+
tool_name = tool_path.stem
|
|
61
|
+
|
|
62
|
+
if tool_name not in ["__init__"]:
|
|
63
|
+
logger.debug("tool_name=<%s> | tool change detected", tool_name)
|
|
64
|
+
try:
|
|
65
|
+
self.tool_registry.reload_tool(tool_name)
|
|
66
|
+
except Exception as e:
|
|
67
|
+
logger.error("tool_name=<%s>, exception=<%s> | failed to reload tool", tool_name, str(e))
|
|
68
|
+
|
|
69
|
+
class MasterChangeHandler(FileSystemEventHandler):
|
|
70
|
+
"""Master handler that delegates to all registered handlers."""
|
|
71
|
+
|
|
72
|
+
def __init__(self, dir_path: str) -> None:
|
|
73
|
+
"""Initialize a master change handler for a specific directory.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
dir_path: The directory path to watch.
|
|
77
|
+
"""
|
|
78
|
+
self.dir_path = dir_path
|
|
79
|
+
|
|
80
|
+
def on_modified(self, event: Any) -> None:
|
|
81
|
+
"""Delegate file modification events to all registered handlers.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
event: The file system event that triggered this handler.
|
|
85
|
+
"""
|
|
86
|
+
if event.src_path.endswith(".py"):
|
|
87
|
+
tool_path = Path(event.src_path)
|
|
88
|
+
tool_name = tool_path.stem
|
|
89
|
+
|
|
90
|
+
if tool_name not in ["__init__"]:
|
|
91
|
+
# Delegate to all registered handlers for this directory
|
|
92
|
+
for handler in ToolWatcher._registry_handlers.get(self.dir_path, {}).values():
|
|
93
|
+
try:
|
|
94
|
+
handler.on_modified(event)
|
|
95
|
+
except Exception as e:
|
|
96
|
+
logger.error("exception=<%s> | handler error", str(e))
|
|
97
|
+
|
|
98
|
+
def start(self) -> None:
|
|
99
|
+
"""Start watching all tools directories for changes."""
|
|
100
|
+
# Initialize shared observer if not already done
|
|
101
|
+
if ToolWatcher._shared_observer is None:
|
|
102
|
+
ToolWatcher._shared_observer = Observer()
|
|
103
|
+
|
|
104
|
+
# Create handler for this instance
|
|
105
|
+
self.tool_change_handler = self.ToolChangeHandler(self.tool_registry)
|
|
106
|
+
registry_id = id(self.tool_registry)
|
|
107
|
+
|
|
108
|
+
# Get tools directories to watch
|
|
109
|
+
tools_dirs = self.tool_registry.get_tools_dirs()
|
|
110
|
+
|
|
111
|
+
for tools_dir in tools_dirs:
|
|
112
|
+
dir_str = str(tools_dir)
|
|
113
|
+
|
|
114
|
+
# Initialize the registry handlers dict for this directory if needed
|
|
115
|
+
if dir_str not in ToolWatcher._registry_handlers:
|
|
116
|
+
ToolWatcher._registry_handlers[dir_str] = {}
|
|
117
|
+
|
|
118
|
+
# Store this handler with its registry id
|
|
119
|
+
ToolWatcher._registry_handlers[dir_str][registry_id] = self.tool_change_handler
|
|
120
|
+
|
|
121
|
+
# Schedule or update the master handler for this directory
|
|
122
|
+
if dir_str not in ToolWatcher._watched_dirs:
|
|
123
|
+
# First time seeing this directory, create a master handler
|
|
124
|
+
master_handler = self.MasterChangeHandler(dir_str)
|
|
125
|
+
ToolWatcher._shared_observer.schedule(master_handler, dir_str, recursive=False)
|
|
126
|
+
ToolWatcher._watched_dirs.add(dir_str)
|
|
127
|
+
logger.debug("tools_dir=<%s> | started watching tools directory", tools_dir)
|
|
128
|
+
else:
|
|
129
|
+
# Directory already being watched, just log it
|
|
130
|
+
logger.debug("tools_dir=<%s> | directory already being watched", tools_dir)
|
|
131
|
+
|
|
132
|
+
# Start the observer if not already started
|
|
133
|
+
if not ToolWatcher._observer_started:
|
|
134
|
+
ToolWatcher._shared_observer.start()
|
|
135
|
+
ToolWatcher._observer_started = True
|
|
136
|
+
logger.debug("tool directory watching initialized")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Generic collection types for the Strands SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import Generic, List, Optional, TypeVar
|
|
4
|
+
|
|
5
|
+
T = TypeVar("T")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PaginatedList(list, Generic[T]):
|
|
9
|
+
"""A generic list-like object that includes a pagination token.
|
|
10
|
+
|
|
11
|
+
This maintains backwards compatibility by inheriting from list,
|
|
12
|
+
so existing code that expects List[T] will continue to work.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, data: List[T], token: Optional[str] = None):
|
|
16
|
+
"""Initialize a PaginatedList with data and an optional pagination token.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
data: The list of items to store.
|
|
20
|
+
token: Optional pagination token for retrieving additional items.
|
|
21
|
+
"""
|
|
22
|
+
super().__init__(data)
|
|
23
|
+
self.pagination_token = token
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Content-related type definitions for the SDK.
|
|
2
|
+
|
|
3
|
+
This module defines the types used to represent messages, content blocks, and other content-related structures in the
|
|
4
|
+
SDK. These types are modeled after the Bedrock API.
|
|
5
|
+
|
|
6
|
+
- Bedrock docs: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Types_Amazon_Bedrock_Runtime.html
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Dict, List, Literal, Optional
|
|
10
|
+
|
|
11
|
+
from typing_extensions import TypedDict
|
|
12
|
+
|
|
13
|
+
from .media import DocumentContent, ImageContent, VideoContent
|
|
14
|
+
from .tools import ToolResult, ToolUse
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class GuardContentText(TypedDict):
|
|
18
|
+
"""Text content to be evaluated by guardrails.
|
|
19
|
+
|
|
20
|
+
Attributes:
|
|
21
|
+
qualifiers: The qualifiers describing the text block.
|
|
22
|
+
text: The input text details to be evaluated by the guardrail.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
qualifiers: List[Literal["grounding_source", "query", "guard_content"]]
|
|
26
|
+
text: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class GuardContent(TypedDict):
|
|
30
|
+
"""Content block to be evaluated by guardrails.
|
|
31
|
+
|
|
32
|
+
Attributes:
|
|
33
|
+
text: Text within content block to be evaluated by the guardrail.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
text: GuardContentText
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ReasoningTextBlock(TypedDict, total=False):
|
|
40
|
+
"""Contains the reasoning that the model used to return the output.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
signature: A token that verifies that the reasoning text was generated by the model.
|
|
44
|
+
text: The reasoning that the model used to return the output.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
signature: Optional[str]
|
|
48
|
+
text: str
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ReasoningContentBlock(TypedDict, total=False):
|
|
52
|
+
"""Contains content regarding the reasoning that is carried out by the model.
|
|
53
|
+
|
|
54
|
+
Attributes:
|
|
55
|
+
reasoningText: The reasoning that the model used to return the output.
|
|
56
|
+
redactedContent: The content in the reasoning that was encrypted by the model provider for safety reasons.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
reasoningText: ReasoningTextBlock
|
|
60
|
+
redactedContent: bytes
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class CachePoint(TypedDict):
|
|
64
|
+
"""A cache point configuration for optimizing conversation history.
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
type: The type of cache point, typically "default".
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
type: str
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ContentBlock(TypedDict, total=False):
|
|
74
|
+
"""A block of content for a message that you pass to, or receive from, a model.
|
|
75
|
+
|
|
76
|
+
Attributes:
|
|
77
|
+
cachePoint: A cache point configuration to optimize conversation history.
|
|
78
|
+
document: A document to include in the message.
|
|
79
|
+
guardContent: Contains the content to assess with the guardrail.
|
|
80
|
+
image: Image to include in the message.
|
|
81
|
+
reasoningContent: Contains content regarding the reasoning that is carried out by the model.
|
|
82
|
+
text: Text to include in the message.
|
|
83
|
+
toolResult: The result for a tool request that a model makes.
|
|
84
|
+
toolUse: Information about a tool use request from a model.
|
|
85
|
+
video: Video to include in the message.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
cachePoint: CachePoint
|
|
89
|
+
document: DocumentContent
|
|
90
|
+
guardContent: GuardContent
|
|
91
|
+
image: ImageContent
|
|
92
|
+
reasoningContent: ReasoningContentBlock
|
|
93
|
+
text: str
|
|
94
|
+
toolResult: ToolResult
|
|
95
|
+
toolUse: ToolUse
|
|
96
|
+
video: VideoContent
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class SystemContentBlock(TypedDict, total=False):
|
|
100
|
+
"""Contains configurations for instructions to provide the model for how to handle input.
|
|
101
|
+
|
|
102
|
+
Attributes:
|
|
103
|
+
guardContent: A content block to assess with the guardrail.
|
|
104
|
+
text: A system prompt for the model.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
guardContent: GuardContent
|
|
108
|
+
text: str
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class DeltaContent(TypedDict, total=False):
|
|
112
|
+
"""A block of content in a streaming response.
|
|
113
|
+
|
|
114
|
+
Attributes:
|
|
115
|
+
text: The content text.
|
|
116
|
+
toolUse: Information about a tool that the model is requesting to use.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
text: str
|
|
120
|
+
toolUse: Dict[Literal["input"], str]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class ContentBlockStartToolUse(TypedDict):
|
|
124
|
+
"""The start of a tool use block.
|
|
125
|
+
|
|
126
|
+
Attributes:
|
|
127
|
+
name: The name of the tool that the model is requesting to use.
|
|
128
|
+
toolUseId: The ID for the tool request.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
name: str
|
|
132
|
+
toolUseId: str
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class ContentBlockStart(TypedDict, total=False):
|
|
136
|
+
"""Content block start information.
|
|
137
|
+
|
|
138
|
+
Attributes:
|
|
139
|
+
toolUse: Information about a tool that the model is requesting to use.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
toolUse: Optional[ContentBlockStartToolUse]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class ContentBlockDelta(TypedDict):
|
|
146
|
+
"""The content block delta event.
|
|
147
|
+
|
|
148
|
+
Attributes:
|
|
149
|
+
contentBlockIndex: The block index for a content block delta event.
|
|
150
|
+
delta: The delta for a content block delta event.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
contentBlockIndex: int
|
|
154
|
+
delta: DeltaContent
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class ContentBlockStop(TypedDict):
|
|
158
|
+
"""A content block stop event.
|
|
159
|
+
|
|
160
|
+
Attributes:
|
|
161
|
+
contentBlockIndex: The index for a content block.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
contentBlockIndex: int
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
Role = Literal["user", "assistant"]
|
|
168
|
+
"""Role of a message sender.
|
|
169
|
+
|
|
170
|
+
- "user": Messages from the user to the assistant
|
|
171
|
+
- "assistant": Messages from the assistant to the user
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class Message(TypedDict):
|
|
176
|
+
"""A message in a conversation with the agent.
|
|
177
|
+
|
|
178
|
+
Attributes:
|
|
179
|
+
content: The message content.
|
|
180
|
+
role: The role of the message sender.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
content: List[ContentBlock]
|
|
184
|
+
role: Role
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
Messages = List[Message]
|
|
188
|
+
"""A list of messages representing a conversation."""
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Event loop-related type definitions for the SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from typing_extensions import TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Usage(TypedDict):
|
|
9
|
+
"""Token usage information for model interactions.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
inputTokens: Number of tokens sent in the request to the model..
|
|
13
|
+
outputTokens: Number of tokens that the model generated for the request.
|
|
14
|
+
totalTokens: Total number of tokens (input + output).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
inputTokens: int
|
|
18
|
+
outputTokens: int
|
|
19
|
+
totalTokens: int
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Metrics(TypedDict):
|
|
23
|
+
"""Performance metrics for model interactions.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
latencyMs (int): Latency of the model request in milliseconds.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
latencyMs: int
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
StopReason = Literal[
|
|
33
|
+
"content_filtered",
|
|
34
|
+
"end_turn",
|
|
35
|
+
"guardrail_intervened",
|
|
36
|
+
"max_tokens",
|
|
37
|
+
"stop_sequence",
|
|
38
|
+
"tool_use",
|
|
39
|
+
]
|
|
40
|
+
"""Reason for the model ending its response generation.
|
|
41
|
+
|
|
42
|
+
- "content_filtered": Content was filtered due to policy violation
|
|
43
|
+
- "end_turn": Normal completion of the response
|
|
44
|
+
- "guardrail_intervened": Guardrail system intervened
|
|
45
|
+
- "max_tokens": Maximum token limit reached
|
|
46
|
+
- "stop_sequence": Stop sequence encountered
|
|
47
|
+
- "tool_use": Model requested to use a tool
|
|
48
|
+
"""
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Exception-related type definitions for the SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from .content import Message
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EventLoopException(Exception):
|
|
9
|
+
"""Exception raised by the event loop."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, original_exception: Exception, request_state: Any = None) -> None:
|
|
12
|
+
"""Initialize exception.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
original_exception: The original exception that was raised.
|
|
16
|
+
request_state: The state of the request at the time of the exception.
|
|
17
|
+
"""
|
|
18
|
+
self.original_exception = original_exception
|
|
19
|
+
self.request_state = request_state if request_state is not None else {}
|
|
20
|
+
super().__init__(str(original_exception))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MaxTokensReachedException(Exception):
|
|
24
|
+
"""Exception raised when the model reaches its maximum token generation limit.
|
|
25
|
+
|
|
26
|
+
This exception is raised when the model stops generating tokens because it has reached the maximum number of
|
|
27
|
+
tokens allowed for output generation. This can occur when the model's max_tokens parameter is set too low for
|
|
28
|
+
the complexity of the response, or when the model naturally reaches its configured output limit during generation.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, message: str, incomplete_message: Message):
|
|
32
|
+
"""Initialize the exception with an error message and the incomplete message object.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
message: The error message describing the token limit issue
|
|
36
|
+
incomplete_message: The valid Message object with incomplete content due to token limits
|
|
37
|
+
"""
|
|
38
|
+
self.incomplete_message = incomplete_message
|
|
39
|
+
super().__init__(message)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ContextWindowOverflowException(Exception):
|
|
43
|
+
"""Exception raised when the context window is exceeded.
|
|
44
|
+
|
|
45
|
+
This exception is raised when the input to a model exceeds the maximum context window size that the model can
|
|
46
|
+
handle. This typically occurs when the combined length of the conversation history, system prompt, and current
|
|
47
|
+
message is too large for the model to process.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class MCPClientInitializationError(Exception):
|
|
54
|
+
"""Raised when the MCP server fails to initialize properly."""
|
|
55
|
+
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ModelThrottledException(Exception):
|
|
60
|
+
"""Exception raised when the model is throttled.
|
|
61
|
+
|
|
62
|
+
This exception is raised when the model is throttled by the service. This typically occurs when the service is
|
|
63
|
+
throttling the requests from the client.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
def __init__(self, message: str) -> None:
|
|
67
|
+
"""Initialize exception.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
message: The message from the service that describes the throttling.
|
|
71
|
+
"""
|
|
72
|
+
self.message = message
|
|
73
|
+
super().__init__(message)
|
|
74
|
+
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class SessionException(Exception):
|
|
79
|
+
"""Exception raised when session operations fail."""
|
|
80
|
+
|
|
81
|
+
pass
|