agnt5 0.2.3__cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.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 ADDED
@@ -0,0 +1,86 @@
1
+ """
2
+ AGNT5 Python SDK - Build durable, resilient agent-first applications.
3
+
4
+ This SDK provides high-level components for building agents, tools, and workflows
5
+ with built-in durability guarantees and state management.
6
+ """
7
+
8
+ from ._compat import _import_error, _rust_available
9
+ from .agent import Agent, AgentRegistry, AgentResult, Handoff, agent, handoff
10
+ from .client import Client, RunError
11
+ from .context import Context
12
+ from .entity import (
13
+ DurableEntity,
14
+ SessionEntity,
15
+ MemoryEntity,
16
+ WorkflowEntity,
17
+ EntityInstance,
18
+ EntityRegistry,
19
+ EntityType,
20
+ entity,
21
+ )
22
+ from .exceptions import (
23
+ AGNT5Error,
24
+ CheckpointError,
25
+ ConfigurationError,
26
+ ExecutionError,
27
+ RetryError,
28
+ StateError,
29
+ )
30
+ from .function import FunctionRegistry, function
31
+ from .tool import Tool, ToolRegistry, tool
32
+ from .types import BackoffPolicy, BackoffType, FunctionConfig, RetryPolicy, WorkflowConfig
33
+ from .version import _get_version
34
+ from .worker import Worker
35
+ from .workflow import WorkflowRegistry, workflow
36
+
37
+ # Expose simplified language model API (recommended)
38
+ from . import lm
39
+
40
+ __version__ = _get_version()
41
+
42
+ __all__ = [
43
+ # Version
44
+ "__version__",
45
+ # Core components
46
+ "Context",
47
+ "Client",
48
+ "Worker",
49
+ "function",
50
+ "FunctionRegistry",
51
+ "entity",
52
+ "EntityType",
53
+ "EntityInstance",
54
+ "EntityRegistry",
55
+ "DurableEntity",
56
+ "SessionEntity",
57
+ "MemoryEntity",
58
+ "WorkflowEntity",
59
+ "workflow",
60
+ "WorkflowRegistry",
61
+ "tool",
62
+ "Tool",
63
+ "ToolRegistry",
64
+ "agent",
65
+ "Agent",
66
+ "AgentRegistry",
67
+ "AgentResult",
68
+ "Handoff",
69
+ "handoff",
70
+ # Types
71
+ "RetryPolicy",
72
+ "BackoffPolicy",
73
+ "BackoffType",
74
+ "FunctionConfig",
75
+ "WorkflowConfig",
76
+ # Exceptions
77
+ "AGNT5Error",
78
+ "ConfigurationError",
79
+ "ExecutionError",
80
+ "RetryError",
81
+ "StateError",
82
+ "CheckpointError",
83
+ "RunError",
84
+ # Language Model (Simplified API)
85
+ "lm",
86
+ ]
agnt5/_compat.py ADDED
@@ -0,0 +1,16 @@
1
+ """
2
+ Compatibility utilities for the AGNT5 Python SDK.
3
+
4
+ This module handles runtime compatibility checks and provides utilities
5
+ for cross-referencing throughout the project.
6
+ """
7
+
8
+ # Check if Rust core is available
9
+ try:
10
+ from . import _core
11
+
12
+ _rust_available = True
13
+ _import_error = None
14
+ except ImportError as e:
15
+ _rust_available = False
16
+ _import_error = e
agnt5/_core.abi3.so ADDED
Binary file
agnt5/_telemetry.py ADDED
@@ -0,0 +1,146 @@
1
+ """
2
+ OpenTelemetry integration for Python logging.
3
+
4
+ This module bridges Python's standard logging to Rust's tracing/OpenTelemetry system,
5
+ ensuring all logs from ctx.logger are sent to both the console and OTLP exporters.
6
+ """
7
+
8
+ import logging
9
+ from typing import Optional
10
+
11
+
12
+ class OpenTelemetryHandler(logging.Handler):
13
+ """
14
+ Custom logging handler that forwards Python logs to Rust OpenTelemetry system.
15
+
16
+ This handler routes all Python log records through the Rust `log_from_python()`
17
+ function, which integrates with the tracing ecosystem. This ensures:
18
+
19
+ 1. Logs are sent to OpenTelemetry OTLP exporter
20
+ 2. Logs appear in console output (via Rust's fmt layer)
21
+ 3. Logs inherit span context (invocation.id, trace_id, etc.)
22
+ 4. Structured logging with proper attributes
23
+
24
+ The Rust side handles both console output and OTLP export, so we only
25
+ need one handler on the Python side.
26
+ """
27
+
28
+ def __init__(self, level=logging.NOTSET):
29
+ """Initialize the OpenTelemetry handler.
30
+
31
+ Args:
32
+ level: Minimum log level to process (default: NOTSET processes all)
33
+ """
34
+ super().__init__(level)
35
+
36
+ # Import Rust bridge function
37
+ try:
38
+ from ._core import log_from_python
39
+ self._log_from_python = log_from_python
40
+ except ImportError as e:
41
+ # Fallback if Rust core not available (development/testing)
42
+ import warnings
43
+ warnings.warn(
44
+ f"Failed to import Rust telemetry bridge: {e}. "
45
+ "Logs will not be sent to OpenTelemetry.",
46
+ RuntimeWarning
47
+ )
48
+ self._log_from_python = None
49
+
50
+ def emit(self, record: logging.LogRecord):
51
+ """
52
+ Process a log record and forward to Rust telemetry.
53
+
54
+ Args:
55
+ record: Python logging record to process
56
+ """
57
+ if self._log_from_python is None:
58
+ # No Rust bridge available, silently skip
59
+ return
60
+
61
+ # Filter out gRPC internal logs to avoid noise
62
+ # These are low-level HTTP/2 protocol logs that aren't useful for application debugging
63
+ if record.name.startswith(('grpc.', 'h2.', '_grpc_', 'h2-')):
64
+ return
65
+
66
+ try:
67
+ # Format the message (applies any formatters)
68
+ message = self.format(record)
69
+
70
+ # Forward to Rust tracing system
71
+ # Rust side will:
72
+ # - Add to current span context (inherits invocation.id)
73
+ # - Send to OTLP exporter
74
+ # - Print to console via fmt layer
75
+ self._log_from_python(
76
+ level=record.levelname,
77
+ message=message,
78
+ target=record.name,
79
+ module_path=record.module,
80
+ filename=record.pathname,
81
+ line=record.lineno
82
+ )
83
+ except Exception:
84
+ # Don't let logging errors crash the application
85
+ # Use handleError to report the issue via logging system
86
+ self.handleError(record)
87
+
88
+
89
+ def setup_context_logger(logger: logging.Logger, log_level: Optional[int] = None) -> None:
90
+ """
91
+ Configure a Context logger with OpenTelemetry integration.
92
+
93
+ This function:
94
+ 1. Removes any existing handlers (avoid duplicates)
95
+ 2. Adds OpenTelemetry handler for OTLP + console output
96
+ 3. Sets appropriate log level
97
+ 4. Disables propagation to avoid duplicate logs
98
+
99
+ Args:
100
+ logger: Logger instance to configure
101
+ log_level: Optional log level (default: DEBUG)
102
+ """
103
+ # Remove existing handlers to avoid duplicate logs
104
+ logger.handlers.clear()
105
+
106
+ # Add OpenTelemetry handler
107
+ otel_handler = OpenTelemetryHandler()
108
+ otel_handler.setLevel(logging.DEBUG)
109
+
110
+ # Use simple formatter - Rust side handles structured logging
111
+ # We just want the message here
112
+ formatter = logging.Formatter('%(message)s')
113
+ otel_handler.setFormatter(formatter)
114
+
115
+ logger.addHandler(otel_handler)
116
+
117
+ # Set log level (default to DEBUG to let Rust side filter)
118
+ if log_level is None:
119
+ log_level = logging.DEBUG
120
+ logger.setLevel(log_level)
121
+
122
+ # Don't propagate to root logger (we handle everything via OpenTelemetry)
123
+ logger.propagate = False
124
+
125
+
126
+ def setup_module_logger(module_name: str, log_level: Optional[int] = None) -> logging.Logger:
127
+ """
128
+ Create and configure a logger for a module with OpenTelemetry integration.
129
+
130
+ Convenience function for setting up loggers in SDK modules.
131
+
132
+ Args:
133
+ module_name: Name of the module (e.g., "agnt5.worker")
134
+ log_level: Optional log level (default: INFO for modules)
135
+
136
+ Returns:
137
+ Configured logger instance
138
+ """
139
+ logger = logging.getLogger(module_name)
140
+
141
+ # For module loggers, default to INFO level
142
+ if log_level is None:
143
+ log_level = logging.INFO
144
+
145
+ setup_context_logger(logger, log_level)
146
+ return logger