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.

Files changed (115) hide show
  1. agentrun_operation_sdk/cli/__init__.py +1 -0
  2. agentrun_operation_sdk/cli/cli.py +19 -0
  3. agentrun_operation_sdk/cli/common.py +21 -0
  4. agentrun_operation_sdk/cli/runtime/__init__.py +1 -0
  5. agentrun_operation_sdk/cli/runtime/commands.py +203 -0
  6. agentrun_operation_sdk/client/client.py +75 -0
  7. agentrun_operation_sdk/operations/runtime/__init__.py +8 -0
  8. agentrun_operation_sdk/operations/runtime/configure.py +101 -0
  9. agentrun_operation_sdk/operations/runtime/launch.py +82 -0
  10. agentrun_operation_sdk/operations/runtime/models.py +31 -0
  11. agentrun_operation_sdk/services/runtime.py +152 -0
  12. agentrun_operation_sdk/utils/logging_config.py +72 -0
  13. agentrun_operation_sdk/utils/runtime/config.py +94 -0
  14. agentrun_operation_sdk/utils/runtime/container.py +280 -0
  15. agentrun_operation_sdk/utils/runtime/entrypoint.py +203 -0
  16. agentrun_operation_sdk/utils/runtime/schema.py +56 -0
  17. agentrun_sdk/__init__.py +7 -0
  18. agentrun_sdk/agent/__init__.py +25 -0
  19. agentrun_sdk/agent/agent.py +696 -0
  20. agentrun_sdk/agent/agent_result.py +46 -0
  21. agentrun_sdk/agent/conversation_manager/__init__.py +26 -0
  22. agentrun_sdk/agent/conversation_manager/conversation_manager.py +88 -0
  23. agentrun_sdk/agent/conversation_manager/null_conversation_manager.py +46 -0
  24. agentrun_sdk/agent/conversation_manager/sliding_window_conversation_manager.py +179 -0
  25. agentrun_sdk/agent/conversation_manager/summarizing_conversation_manager.py +252 -0
  26. agentrun_sdk/agent/state.py +97 -0
  27. agentrun_sdk/event_loop/__init__.py +9 -0
  28. agentrun_sdk/event_loop/event_loop.py +499 -0
  29. agentrun_sdk/event_loop/streaming.py +319 -0
  30. agentrun_sdk/experimental/__init__.py +4 -0
  31. agentrun_sdk/experimental/hooks/__init__.py +15 -0
  32. agentrun_sdk/experimental/hooks/events.py +123 -0
  33. agentrun_sdk/handlers/__init__.py +10 -0
  34. agentrun_sdk/handlers/callback_handler.py +70 -0
  35. agentrun_sdk/hooks/__init__.py +49 -0
  36. agentrun_sdk/hooks/events.py +80 -0
  37. agentrun_sdk/hooks/registry.py +247 -0
  38. agentrun_sdk/models/__init__.py +10 -0
  39. agentrun_sdk/models/anthropic.py +432 -0
  40. agentrun_sdk/models/bedrock.py +649 -0
  41. agentrun_sdk/models/litellm.py +225 -0
  42. agentrun_sdk/models/llamaapi.py +438 -0
  43. agentrun_sdk/models/mistral.py +539 -0
  44. agentrun_sdk/models/model.py +95 -0
  45. agentrun_sdk/models/ollama.py +357 -0
  46. agentrun_sdk/models/openai.py +436 -0
  47. agentrun_sdk/models/sagemaker.py +598 -0
  48. agentrun_sdk/models/writer.py +449 -0
  49. agentrun_sdk/multiagent/__init__.py +22 -0
  50. agentrun_sdk/multiagent/a2a/__init__.py +15 -0
  51. agentrun_sdk/multiagent/a2a/executor.py +148 -0
  52. agentrun_sdk/multiagent/a2a/server.py +252 -0
  53. agentrun_sdk/multiagent/base.py +92 -0
  54. agentrun_sdk/multiagent/graph.py +555 -0
  55. agentrun_sdk/multiagent/swarm.py +656 -0
  56. agentrun_sdk/py.typed +1 -0
  57. agentrun_sdk/session/__init__.py +18 -0
  58. agentrun_sdk/session/file_session_manager.py +216 -0
  59. agentrun_sdk/session/repository_session_manager.py +152 -0
  60. agentrun_sdk/session/s3_session_manager.py +272 -0
  61. agentrun_sdk/session/session_manager.py +73 -0
  62. agentrun_sdk/session/session_repository.py +51 -0
  63. agentrun_sdk/telemetry/__init__.py +21 -0
  64. agentrun_sdk/telemetry/config.py +194 -0
  65. agentrun_sdk/telemetry/metrics.py +476 -0
  66. agentrun_sdk/telemetry/metrics_constants.py +15 -0
  67. agentrun_sdk/telemetry/tracer.py +563 -0
  68. agentrun_sdk/tools/__init__.py +17 -0
  69. agentrun_sdk/tools/decorator.py +569 -0
  70. agentrun_sdk/tools/executor.py +137 -0
  71. agentrun_sdk/tools/loader.py +152 -0
  72. agentrun_sdk/tools/mcp/__init__.py +13 -0
  73. agentrun_sdk/tools/mcp/mcp_agent_tool.py +99 -0
  74. agentrun_sdk/tools/mcp/mcp_client.py +423 -0
  75. agentrun_sdk/tools/mcp/mcp_instrumentation.py +322 -0
  76. agentrun_sdk/tools/mcp/mcp_types.py +63 -0
  77. agentrun_sdk/tools/registry.py +607 -0
  78. agentrun_sdk/tools/structured_output.py +421 -0
  79. agentrun_sdk/tools/tools.py +217 -0
  80. agentrun_sdk/tools/watcher.py +136 -0
  81. agentrun_sdk/types/__init__.py +5 -0
  82. agentrun_sdk/types/collections.py +23 -0
  83. agentrun_sdk/types/content.py +188 -0
  84. agentrun_sdk/types/event_loop.py +48 -0
  85. agentrun_sdk/types/exceptions.py +81 -0
  86. agentrun_sdk/types/guardrails.py +254 -0
  87. agentrun_sdk/types/media.py +89 -0
  88. agentrun_sdk/types/session.py +152 -0
  89. agentrun_sdk/types/streaming.py +201 -0
  90. agentrun_sdk/types/tools.py +258 -0
  91. agentrun_sdk/types/traces.py +5 -0
  92. agentrun_sdk-0.1.2.dist-info/METADATA +51 -0
  93. agentrun_sdk-0.1.2.dist-info/RECORD +115 -0
  94. agentrun_sdk-0.1.2.dist-info/WHEEL +5 -0
  95. agentrun_sdk-0.1.2.dist-info/entry_points.txt +2 -0
  96. agentrun_sdk-0.1.2.dist-info/top_level.txt +3 -0
  97. agentrun_wrapper/__init__.py +11 -0
  98. agentrun_wrapper/_utils/__init__.py +6 -0
  99. agentrun_wrapper/_utils/endpoints.py +16 -0
  100. agentrun_wrapper/identity/__init__.py +5 -0
  101. agentrun_wrapper/identity/auth.py +211 -0
  102. agentrun_wrapper/memory/__init__.py +6 -0
  103. agentrun_wrapper/memory/client.py +1697 -0
  104. agentrun_wrapper/memory/constants.py +103 -0
  105. agentrun_wrapper/memory/controlplane.py +626 -0
  106. agentrun_wrapper/py.typed +1 -0
  107. agentrun_wrapper/runtime/__init__.py +13 -0
  108. agentrun_wrapper/runtime/app.py +473 -0
  109. agentrun_wrapper/runtime/context.py +34 -0
  110. agentrun_wrapper/runtime/models.py +25 -0
  111. agentrun_wrapper/services/__init__.py +1 -0
  112. agentrun_wrapper/services/identity.py +192 -0
  113. agentrun_wrapper/tools/__init__.py +6 -0
  114. agentrun_wrapper/tools/browser_client.py +325 -0
  115. agentrun_wrapper/tools/code_interpreter_client.py +186 -0
@@ -0,0 +1,211 @@
1
+ """Authentication decorators and utilities for Bedrock AgentCore SDK."""
2
+
3
+ import asyncio
4
+ import contextvars
5
+ import logging
6
+ import os
7
+ from functools import wraps
8
+ from typing import Any, Callable, List, Literal, Optional
9
+
10
+ import boto3
11
+
12
+ from bedrock_agentcore.runtime import BedrockAgentCoreContext
13
+ from bedrock_agentcore.services.identity import IdentityClient, TokenPoller
14
+
15
+ logger = logging.getLogger("bedrock_agentcore.auth")
16
+ logger.setLevel("INFO")
17
+ if not logger.handlers:
18
+ logger.addHandler(logging.StreamHandler())
19
+
20
+
21
+ def requires_access_token(
22
+ *,
23
+ provider_name: str,
24
+ into: str = "access_token",
25
+ scopes: List[str],
26
+ on_auth_url: Optional[Callable[[str], Any]] = None,
27
+ auth_flow: Literal["M2M", "USER_FEDERATION"],
28
+ callback_url: Optional[str] = None,
29
+ force_authentication: bool = False,
30
+ token_poller: Optional[TokenPoller] = None,
31
+ ) -> Callable:
32
+ """Decorator that fetches an OAuth2 access token before calling the decorated function.
33
+
34
+ Args:
35
+ provider_name: The credential provider name
36
+ into: Parameter name to inject the token into
37
+ scopes: OAuth2 scopes to request
38
+ on_auth_url: Callback for handling authorization URLs
39
+ auth_flow: Authentication flow type ("M2M" or "USER_FEDERATION")
40
+ callback_url: OAuth2 callback URL
41
+ force_authentication: Force re-authentication
42
+ token_poller: Custom token poller implementation
43
+
44
+ Returns:
45
+ Decorator function
46
+ """
47
+
48
+ def decorator(func: Callable) -> Callable:
49
+ client = IdentityClient(_get_region())
50
+
51
+ async def _get_token() -> str:
52
+ """Common token fetching logic."""
53
+ return await client.get_token(
54
+ provider_name=provider_name,
55
+ agent_identity_token=await _get_workload_access_token(client),
56
+ scopes=scopes,
57
+ on_auth_url=on_auth_url,
58
+ auth_flow=auth_flow,
59
+ callback_url=callback_url,
60
+ force_authentication=force_authentication,
61
+ token_poller=token_poller,
62
+ )
63
+
64
+ @wraps(func)
65
+ async def async_wrapper(*args: Any, **kwargs_func: Any) -> Any:
66
+ token = await _get_token()
67
+ kwargs_func[into] = token
68
+ return await func(*args, **kwargs_func)
69
+
70
+ @wraps(func)
71
+ def sync_wrapper(*args: Any, **kwargs_func: Any) -> Any:
72
+ if _has_running_loop():
73
+ # for async env, eg. runtime
74
+ ctx = contextvars.copy_context()
75
+ import concurrent.futures
76
+
77
+ with concurrent.futures.ThreadPoolExecutor() as executor:
78
+ future = executor.submit(ctx.run, asyncio.run, _get_token())
79
+ token = future.result()
80
+ else:
81
+ # for sync env, eg. local dev
82
+ token = asyncio.run(_get_token())
83
+
84
+ kwargs_func[into] = token
85
+ return func(*args, **kwargs_func)
86
+
87
+ # Return appropriate wrapper based on function type
88
+ if asyncio.iscoroutinefunction(func):
89
+ return async_wrapper
90
+ else:
91
+ return sync_wrapper
92
+
93
+ return decorator
94
+
95
+
96
+ def requires_api_key(*, provider_name: str, into: str = "api_key") -> Callable:
97
+ """Decorator that fetches an API key before calling the decorated function.
98
+
99
+ Args:
100
+ provider_name: The credential provider name
101
+ into: Parameter name to inject the API key into
102
+
103
+ Returns:
104
+ Decorator function
105
+ """
106
+
107
+ def decorator(func: Callable) -> Callable:
108
+ client = IdentityClient(_get_region())
109
+
110
+ async def _get_api_key():
111
+ return await client.get_api_key(
112
+ provider_name=provider_name,
113
+ agent_identity_token=await _get_workload_access_token(client),
114
+ )
115
+
116
+ @wraps(func)
117
+ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
118
+ api_key = await _get_api_key()
119
+ kwargs[into] = api_key
120
+ return await func(*args, **kwargs)
121
+
122
+ @wraps(func)
123
+ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
124
+ if _has_running_loop():
125
+ # for async env, eg. runtime
126
+ ctx = contextvars.copy_context()
127
+ import concurrent.futures
128
+
129
+ with concurrent.futures.ThreadPoolExecutor() as executor:
130
+ future = executor.submit(ctx.run, asyncio.run, _get_api_key())
131
+ api_key = future.result()
132
+ else:
133
+ # for sync env, eg. local dev
134
+ api_key = asyncio.run(_get_api_key())
135
+
136
+ kwargs[into] = api_key
137
+ return func(*args, **kwargs)
138
+
139
+ if asyncio.iscoroutinefunction(func):
140
+ return async_wrapper
141
+ else:
142
+ return sync_wrapper
143
+
144
+ return decorator
145
+
146
+
147
+ async def _get_workload_access_token(client: IdentityClient) -> str:
148
+ token = BedrockAgentCoreContext.get_workload_access_token()
149
+ if token is not None:
150
+ return token
151
+ else:
152
+ # workload access token context var was not set, so we should be running in a local dev environment
153
+ if os.getenv("DOCKER_CONTAINER") == "1":
154
+ raise ValueError("Workload access token has not been set.")
155
+
156
+ return await _set_up_local_auth(client)
157
+
158
+
159
+ async def _set_up_local_auth(client: IdentityClient) -> str:
160
+ import json
161
+ import uuid
162
+ from pathlib import Path
163
+
164
+ config_path = Path(".agentcore.json")
165
+ workload_identity_name = None
166
+ config = {}
167
+ if config_path.exists():
168
+ try:
169
+ with open(config_path, "r", encoding="utf-8") as file:
170
+ config = json.load(file) or {}
171
+ except Exception:
172
+ print("Could not find existing workload identity and user id")
173
+
174
+ workload_identity_name = config.get("workload_identity_name")
175
+ if workload_identity_name:
176
+ print(f"Found existing workload identity from {config_path.absolute()}: {workload_identity_name}")
177
+ else:
178
+ workload_identity_name = client.create_workload_identity()["name"]
179
+ print("Created a workload identity")
180
+
181
+ user_id = config.get("user_id")
182
+ if user_id:
183
+ print(f"Found existing user id from {config_path.absolute()}: {user_id}")
184
+ else:
185
+ user_id = uuid.uuid4().hex[:8]
186
+ print("Created an user id")
187
+
188
+ try:
189
+ config = {"workload_identity_name": workload_identity_name, "user_id": user_id}
190
+ with open(config_path, "w", encoding="utf-8") as file:
191
+ json.dump(config, file, indent=2)
192
+ except Exception:
193
+ print("Warning: could not write the created workload identity to file")
194
+
195
+ return client.get_workload_access_token(workload_identity_name, user_id=user_id)["workloadAccessToken"]
196
+
197
+
198
+ def _get_region() -> str:
199
+ region_env = os.getenv("AWS_REGION", None)
200
+ if region_env is not None:
201
+ return region_env
202
+
203
+ return boto3.Session().region_name or "us-west-2"
204
+
205
+
206
+ def _has_running_loop() -> bool:
207
+ try:
208
+ asyncio.get_running_loop()
209
+ return True
210
+ except RuntimeError:
211
+ return False
@@ -0,0 +1,6 @@
1
+ """Bedrock AgentCore Memory module for agent memory management capabilities."""
2
+
3
+ from .client import MemoryClient
4
+ from .controlplane import MemoryControlPlaneClient
5
+
6
+ __all__ = ["MemoryClient", "MemoryControlPlaneClient"]