agnt5 0.2.8a9__cp310-abi3-manylinux_2_34_aarch64.whl → 0.3.7a4__cp310-abi3-manylinux_2_34_aarch64.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 agnt5 might be problematic. Click here for more details.

agnt5/__init__.py CHANGED
@@ -1,91 +1,181 @@
1
1
  """
2
2
  AGNT5 Python SDK - Build durable, resilient agent-first applications.
3
3
 
4
- This SDK provides high-level components for building agents, tools, and workflows
5
- with built-in durability guarantees and state management.
4
+ Supports functions, entities, workflows, agents, and LLM integration.
6
5
  """
7
6
 
8
- from ._compat import _import_error, _rust_available
9
- from .agent import Agent, AgentContext, AgentRegistry, AgentResult, Handoff, agent, handoff
10
- from .client import Client, RunError
7
+ from . import events
8
+ from . import lm
9
+ from .agent import (
10
+ Agent,
11
+ AgentCompleted,
12
+ AgentContext,
13
+ AgentFailed,
14
+ AgentIterationCompleted,
15
+ AgentIterationStarted,
16
+ AgentRegistry,
17
+ AgentResult,
18
+ AgentStarted,
19
+ Handoff,
20
+ ToolCallCompleted,
21
+ ToolCallFailed,
22
+ ToolCallStarted,
23
+ agent,
24
+ handoff,
25
+ )
26
+ from .client import AsyncClient, Client, ReceivedEvent, RunError
11
27
  from .context import Context
12
- from .function import FunctionContext
13
- from .workflow import WorkflowContext
14
28
  from .entity import (
15
29
  Entity,
16
30
  EntityRegistry,
17
31
  EntityStateAdapter,
18
32
  EntityType,
33
+ StateType,
19
34
  create_entity_context,
35
+ query,
20
36
  with_entity_context,
21
37
  )
38
+ from .events import (
39
+ Cancelled,
40
+ Completed,
41
+ ComponentType,
42
+ Delta,
43
+ Event,
44
+ EventEmitter,
45
+ EventEnvelope,
46
+ Failed,
47
+ LifecycleEvent,
48
+ OperationType,
49
+ OutputDelta,
50
+ OutputStart,
51
+ OutputStop,
52
+ Paused,
53
+ ProgressUpdate,
54
+ Resumed,
55
+ Started,
56
+ StateChanged,
57
+ Timeout,
58
+ )
22
59
  from .exceptions import (
23
60
  AGNT5Error,
24
- CheckpointError,
25
61
  ConfigurationError,
26
62
  ExecutionError,
27
63
  RetryError,
28
- StateError,
29
64
  WaitingForUserInputException,
30
65
  )
31
- from .function import FunctionRegistry, function
32
- from .tool import AskUserTool, RequestApprovalTool, Tool, ToolRegistry, tool
33
- from .types import BackoffPolicy, BackoffType, FunctionConfig, RetryPolicy, WorkflowConfig
66
+ from .function import FunctionContext, FunctionRegistry, function
67
+ from .lm import (
68
+ LMCompleted,
69
+ LMContentBlockCompleted,
70
+ LMContentBlockDelta,
71
+ LMContentBlockStarted,
72
+ LMFailed,
73
+ LMStarted,
74
+ )
75
+ from .types import BackoffPolicy, BackoffType, RetryPolicy, WorkflowConfig
34
76
  from .version import _get_version
35
77
  from .worker import Worker
36
- from .workflow import WorkflowRegistry, workflow
78
+ from .workflow import WorkflowContext, WorkflowRegistry, workflow
37
79
 
38
- # Expose simplified language model API (recommended)
39
- from . import lm
80
+ from .tool import Tool, ToolRegistry, tool
81
+
82
+ # Not yet enabled:
83
+ # from .checkpoint import CheckpointClient
84
+ # from .exceptions import CheckpointError, StateError
85
+ # from .memory import ConversationMemory, MemoryMessage, MemoryMetadata, MemoryResult, MemoryScope, SemanticMemory
86
+ # from .tool import AskUserTool, RequestApprovalTool
87
+ # from .types import FunctionConfig
88
+ # from . import _sentry as sentry
40
89
 
41
90
  __version__ = _get_version()
42
91
 
43
92
  __all__ = [
44
93
  # Version
45
94
  "__version__",
95
+ # Modules
96
+ "events",
97
+ "lm",
46
98
  # Core components
47
99
  "Context",
48
100
  "FunctionContext",
49
- "WorkflowContext",
50
- "AgentContext",
51
- "Client",
52
101
  "Worker",
53
102
  "function",
54
103
  "FunctionRegistry",
104
+ # Entity components
55
105
  "Entity",
56
- "EntityType",
57
106
  "EntityRegistry",
58
107
  "EntityStateAdapter",
59
- "with_entity_context",
108
+ "EntityType",
109
+ "StateType",
60
110
  "create_entity_context",
61
- "workflow",
111
+ "query",
112
+ "with_entity_context",
113
+ # Workflow components
114
+ "WorkflowContext",
62
115
  "WorkflowRegistry",
63
- "tool",
64
- "Tool",
65
- "ToolRegistry",
66
- "AskUserTool",
67
- "RequestApprovalTool",
68
- "agent",
116
+ "workflow",
117
+ "WorkflowConfig",
118
+ # Agent components
69
119
  "Agent",
120
+ "AgentContext",
70
121
  "AgentRegistry",
71
122
  "AgentResult",
72
123
  "Handoff",
124
+ "agent",
73
125
  "handoff",
126
+ # Tool components
127
+ "Tool",
128
+ "ToolRegistry",
129
+ "tool",
130
+ # Agent events
131
+ "AgentCompleted",
132
+ "AgentFailed",
133
+ "AgentIterationCompleted",
134
+ "AgentIterationStarted",
135
+ "AgentStarted",
136
+ "ToolCallCompleted",
137
+ "ToolCallFailed",
138
+ "ToolCallStarted",
139
+ # LM events
140
+ "LMCompleted",
141
+ "LMContentBlockCompleted",
142
+ "LMContentBlockDelta",
143
+ "LMContentBlockStarted",
144
+ "LMFailed",
145
+ "LMStarted",
146
+ # Base events
147
+ "Cancelled",
148
+ "Completed",
149
+ "ComponentType",
150
+ "Delta",
151
+ "Event",
152
+ "EventEmitter",
153
+ "EventEnvelope",
154
+ "Failed",
155
+ "LifecycleEvent",
156
+ "OperationType",
157
+ "OutputDelta",
158
+ "OutputStart",
159
+ "OutputStop",
160
+ "Paused",
161
+ "ProgressUpdate",
162
+ "Resumed",
163
+ "Started",
164
+ "StateChanged",
165
+ "Timeout",
166
+ # Client
167
+ "AsyncClient",
168
+ "Client",
169
+ "ReceivedEvent",
170
+ "RunError",
74
171
  # Types
75
- "RetryPolicy",
76
172
  "BackoffPolicy",
77
173
  "BackoffType",
78
- "FunctionConfig",
79
- "WorkflowConfig",
174
+ "RetryPolicy",
80
175
  # Exceptions
81
176
  "AGNT5Error",
82
177
  "ConfigurationError",
83
178
  "ExecutionError",
84
179
  "RetryError",
85
- "StateError",
86
- "CheckpointError",
87
180
  "WaitingForUserInputException",
88
- "RunError",
89
- # Language Model (Simplified API)
90
- "lm",
91
181
  ]
agnt5/_core.abi3.so CHANGED
Binary file
agnt5/_retry_utils.py CHANGED
@@ -7,6 +7,7 @@ and executing functions with retry logic.
7
7
  from __future__ import annotations
8
8
 
9
9
  import asyncio
10
+ import inspect
10
11
  from typing import Any, Dict, Optional, Union
11
12
 
12
13
  from .exceptions import RetryError
@@ -100,10 +101,11 @@ async def execute_with_retry(
100
101
  retry_policy: RetryPolicy,
101
102
  backoff_policy: BackoffPolicy,
102
103
  needs_context: bool,
104
+ timeout_ms: Optional[int],
103
105
  *args: Any,
104
106
  **kwargs: Any,
105
107
  ) -> Any:
106
- """Execute handler with retry logic.
108
+ """Execute handler with retry logic and optional timeout.
107
109
 
108
110
  Args:
109
111
  handler: The function handler to execute
@@ -111,6 +113,7 @@ async def execute_with_retry(
111
113
  retry_policy: Retry configuration
112
114
  backoff_policy: Backoff configuration
113
115
  needs_context: Whether handler accepts ctx parameter
116
+ timeout_ms: Maximum execution time in milliseconds (None for no timeout)
114
117
  *args: Arguments to pass to handler (excluding ctx if needs_context=False)
115
118
  **kwargs: Keyword arguments to pass to handler
116
119
 
@@ -119,6 +122,7 @@ async def execute_with_retry(
119
122
 
120
123
  Raises:
121
124
  RetryError: If all retry attempts fail
125
+ asyncio.TimeoutError: If function execution exceeds timeout_ms
122
126
  """
123
127
  # Import here to avoid circular dependency
124
128
  from .function import FunctionContext
@@ -128,17 +132,41 @@ async def execute_with_retry(
128
132
  for attempt in range(retry_policy.max_attempts):
129
133
  try:
130
134
  # Create context for this attempt (FunctionContext is immutable)
135
+ # Propagate streaming context from parent for real-time SSE log delivery
131
136
  attempt_ctx = FunctionContext(
132
137
  run_id=ctx.run_id,
138
+ correlation_id=getattr(ctx, 'correlation_id', f"retry-{attempt}"),
139
+ parent_correlation_id=getattr(ctx, 'parent_correlation_id', ctx.run_id),
133
140
  attempt=attempt,
134
- retry_policy=retry_policy
141
+ retry_policy=retry_policy,
142
+ worker=getattr(ctx, '_worker', None),
135
143
  )
136
144
 
137
145
  # Execute handler (pass context only if needed)
138
146
  if needs_context:
139
- result = await handler(attempt_ctx, *args, **kwargs)
147
+ result = handler(attempt_ctx, *args, **kwargs)
140
148
  else:
141
- result = await handler(*args, **kwargs)
149
+ result = handler(*args, **kwargs)
150
+
151
+ # Check if result is an async generator (streaming function)
152
+ # Async generators cannot be retried - return immediately for streaming consumption
153
+ if inspect.isasyncgen(result):
154
+ return result
155
+
156
+ # For coroutines, apply timeout and await
157
+ if inspect.iscoroutine(result):
158
+ if timeout_ms is not None:
159
+ timeout_seconds = timeout_ms / 1000.0
160
+ try:
161
+ result = await asyncio.wait_for(result, timeout=timeout_seconds)
162
+ except asyncio.TimeoutError:
163
+ # Re-raise with more context
164
+ raise asyncio.TimeoutError(
165
+ f"Function execution timed out after {timeout_ms}ms"
166
+ )
167
+ else:
168
+ result = await result
169
+
142
170
  return result
143
171
 
144
172
  except Exception as e:
agnt5/_schema_utils.py CHANGED
@@ -168,19 +168,19 @@ def _type_to_schema(python_type: Any) -> Dict[str, Any]:
168
168
  }
169
169
 
170
170
  # Handle basic types
171
- if python_type == str:
171
+ if python_type is str:
172
172
  return {"type": "string"}
173
- elif python_type == int:
173
+ elif python_type is int:
174
174
  return {"type": "integer"}
175
- elif python_type == float:
175
+ elif python_type is float:
176
176
  return {"type": "number"}
177
- elif python_type == bool:
177
+ elif python_type is bool:
178
178
  return {"type": "boolean"}
179
- elif python_type == dict:
179
+ elif python_type is dict:
180
180
  return {"type": "object"}
181
- elif python_type == list:
181
+ elif python_type is list:
182
182
  return {"type": "array"}
183
- elif python_type == Any:
183
+ elif python_type is Any:
184
184
  return {} # Any type - no restrictions
185
185
 
186
186
  # Fallback for unknown types