Skip to content

Commit 501ea18

Browse files
committed
Making agent_secret required field instead of optional and taking it from the environment variable
1 parent f33f770 commit 501ea18

File tree

9 files changed

+69
-41
lines changed

9 files changed

+69
-41
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ import asyncio
6969
from value import initialize_async
7070

7171
async def main():
72-
client = await initialize_async()
72+
# agent_secret is required
73+
client = await initialize_async(agent_secret="your-agent-secret")
7374

7475
async def process_data(data: str) -> str:
7576
print(f"Processing data: {data}")
@@ -94,9 +95,10 @@ asyncio.run(main())
9495
```python
9596
from value import initialize_sync
9697

97-
client = initialize_sync()
98+
# agent_secret is required
99+
client = initialize_sync(agent_secret="your-agent-secret")
98100

99-
with client.action_context(user_id="user123") as ctx:
101+
with client.action_context(user_id="user123", anonymous_id="anon456") as ctx:
100102
# Your code here
101103
ctx.send(action_name="my_action", **{"custom.attribute": "value"})
102104
```
@@ -108,8 +110,8 @@ Enable automatic tracing for supported AI libraries:
108110
```python
109111
from value import initialize_sync, auto_instrument
110112

111-
# Initialize the client
112-
client = initialize_sync()
113+
# Initialize the client with agent_secret
114+
client = initialize_sync(agent_secret="your-agent-secret")
113115

114116
# Auto-instrument specific libraries
115117
auto_instrument(["gemini", "langchain"])
@@ -124,8 +126,8 @@ auto_instrument()
124126
from value import initialize_sync, auto_instrument
125127
from google import genai
126128

127-
# Initialize Value client and auto-instrument
128-
client = initialize_sync()
129+
# Initialize Value client with agent_secret and auto-instrument
130+
client = initialize_sync(agent_secret="your-agent-secret")
129131
auto_instrument(["gemini"])
130132

131133
# Use Gemini as usual - traces are automatically captured
@@ -140,11 +142,10 @@ print(response.text)
140142

141143
## Configuration
142144

143-
Configure the SDK using environment variables:
145+
The `agent_secret` is passed directly to `initialize_sync()` or `initialize_async()`. Additional configuration can be set using environment variables:
144146

145147
| Variable | Description | Default |
146148
| ---------------------- | ------------------------------------------ | ----------------------- |
147-
| `VALUE_AGENT_SECRET` | Agent authentication secret | Required |
148149
| `VALUE_OTEL_ENDPOINT` | OpenTelemetry collector endpoint | `http://localhost:4317` |
149150
| `VALUE_BACKEND_URL` | Value Control Plane backend URL | Required |
150151
| `VALUE_SERVICE_NAME` | Service name for OpenTelemetry resource | `value-control-agent` |
@@ -161,8 +162,8 @@ Configure the SDK using environment variables:
161162

162163
### Core Functions
163164

164-
- `initialize_sync()` - Initialize a synchronous Value client
165-
- `initialize_async()` - Initialize an asynchronous Value client
165+
- `initialize_sync(agent_secret)` - Initialize a synchronous Value client
166+
- `initialize_async(agent_secret)` - Initialize an asynchronous Value client
166167
- `auto_instrument(libraries=None)` - Enable auto-instrumentation for specified libraries
167168
- `uninstrument(libraries=None)` - Disable auto-instrumentation
168169
- `get_supported_libraries()` - Get list of supported library names

examples/async_example.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""Async example demonstrating the Value SDK usage."""
22

3+
import asyncio
4+
import os
35
from dotenv import load_dotenv
46

57
load_dotenv()
68

7-
import asyncio
89
from value import initialize_async
910

11+
# Get agent secret from environment variable
12+
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
13+
1014

1115
async def main() -> None:
12-
client = await initialize_async()
16+
client = await initialize_async(agent_secret=AGENT_SECRET)
1317

1418
async def process_data(data: str) -> str:
1519
"""Process data with tracing."""

examples/async_example_simple.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""Async example demonstrating the Value SDK usage."""
22

3+
import asyncio
4+
import os
35
from dotenv import load_dotenv
46

57
load_dotenv()
68

7-
import asyncio
89
from value import initialize_async
910

11+
# Get agent secret from environment variable
12+
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
13+
1014

1115
async def main() -> None:
12-
client = await initialize_async()
16+
client = await initialize_async(agent_secret=AGENT_SECRET)
1317

1418
async def process_data(data: str) -> str:
1519
"""Process data with tracing."""

examples/gemini_autoinstrument_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
from dotenv import load_dotenv
21
import os
2+
from dotenv import load_dotenv
33

44
load_dotenv()
55

66
from value.instrumentation import auto_instrument
77
from value import initialize_sync
88
from google import genai
99

10-
value_client = initialize_sync()
10+
# Get agent secret from environment variable
11+
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
12+
13+
value_client = initialize_sync(agent_secret=AGENT_SECRET)
1114
auto_instrument(["gemini"])
1215

1316
api_key = os.getenv("GOOGLE_API_KEY", "your-gemini-api-key-here")

examples/live_data.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import asyncio
12+
import os
1213
import random
1314
import uuid
1415
import time
@@ -22,6 +23,9 @@
2223
from opentelemetry import trace
2324
from opentelemetry.trace import Status, StatusCode
2425

26+
# Get agent secret from environment variable
27+
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
28+
2529
# Synthetic data generators
2630
INVOICE_TYPES = ["invoice", "receipt", "bill", "purchase_order"]
2731
VENDORS = ["Amazon", "Google", "Microsoft", "Apple", "Uber", "Lyft", "Walmart", "Target"]
@@ -253,7 +257,7 @@ async def _simulate_ollama_call(self, user_id: str, anonymous_id: str, invoice_i
253257

254258
async def main():
255259
print("Initializing Value SDK...")
256-
client = await initialize_async()
260+
client = await initialize_async(agent_secret=AGENT_SECRET)
257261
simulator = PipelineSimulator(client)
258262

259263
print("Starting Live Data Simulation (Ctrl+C to stop)...")

examples/sync_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
"""Synchronous example demonstrating the Value SDK usage."""
22

3-
from dotenv import load_dotenv
43
import os
4+
import time
5+
from dotenv import load_dotenv
56

67
load_dotenv()
78

8-
import time
99
from value import initialize_sync
1010

11+
# Get agent secret from environment variable
12+
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
13+
1114

1215
def main() -> None:
13-
client = initialize_sync()
16+
client = initialize_sync(agent_secret=AGENT_SECRET)
1417

1518
def process_data(data: str) -> str:
1619
"""Process data with tracing."""

scripts/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if [ -z "$VERSION" ]; then
1212
exit 1
1313
fi
1414

15-
echo "🚀 Releasing version $VERSION..."
15+
echo "Releasing version $VERSION..."
1616

1717
# Update version in pyproject.toml
1818
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml && rm pyproject.toml.bak

src/value/client.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ class AsyncValueClient:
1515

1616
def __init__(
1717
self,
18+
secret: str,
1819
service_name: str = "value-control-agent",
19-
secret: Optional[str] = None,
2020
otel_endpoint: Optional[str] = None,
2121
backend_url: Optional[str] = None,
2222
enable_console_export: bool = False,
2323
):
2424
config = load_config_from_env()
25-
self.secret = secret or config.secret
26-
if not self.secret:
27-
raise ValueError("Agent secret must be provided.")
25+
self.secret = secret
2826

2927
self._otel_endpoint = otel_endpoint or config.otel_endpoint
3028
self._service_name = service_name
@@ -91,16 +89,14 @@ class ValueClient:
9189

9290
def __init__(
9391
self,
92+
secret: str,
9493
service_name: str = "value-control-agent",
95-
secret: Optional[str] = None,
9694
otel_endpoint: Optional[str] = None,
9795
backend_url: Optional[str] = None,
9896
enable_console_export: bool = False,
9997
):
10098
config = load_config_from_env()
101-
self.secret = secret or config.secret
102-
if not self.secret:
103-
raise ValueError("Agent secret must be provided.")
99+
self.secret = secret
104100

105101
self._otel_endpoint = otel_endpoint or config.otel_endpoint
106102
self._service_name = service_name
@@ -163,21 +159,39 @@ def initialize(self) -> None:
163159
self.actions_emitter = ActionEmitter(tracer=self._tracer)
164160

165161

166-
def initialize_sync(service_name: str = "value-control-agent") -> ValueClient:
162+
def initialize_sync(
163+
agent_secret: str,
164+
service_name: str = "value-control-agent",
165+
) -> ValueClient:
167166
"""
168167
Initialize and return a configured synchronous ValueClient instance.
169-
Reads configuration from environment variables.
168+
169+
Args:
170+
agent_secret: The agent secret for authentication (required).
171+
service_name: The service name for OpenTelemetry resource.
172+
173+
Returns:
174+
A configured ValueClient instance.
170175
"""
171-
client = ValueClient(service_name=service_name)
176+
client = ValueClient(secret=agent_secret, service_name=service_name)
172177
client.initialize()
173178
return client
174179

175180

176-
async def initialize_async(service_name: str = "value-control-agent") -> AsyncValueClient:
181+
async def initialize_async(
182+
agent_secret: str,
183+
service_name: str = "value-control-agent",
184+
) -> AsyncValueClient:
177185
"""
178186
Initialize and return a configured asynchronous AsyncValueClient instance.
179-
Reads configuration from environment variables.
187+
188+
Args:
189+
agent_secret: The agent secret for authentication (required).
190+
service_name: The service name for OpenTelemetry resource.
191+
192+
Returns:
193+
A configured AsyncValueClient instance.
180194
"""
181-
client = AsyncValueClient(service_name=service_name)
195+
client = AsyncValueClient(secret=agent_secret, service_name=service_name)
182196
await client.initialize()
183197
return client

src/value/internal/config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@
99
class SDKConfig:
1010
"""Configuration for the Value SDK."""
1111

12-
secret: str
1312
otel_endpoint: str = "http://localhost:4317"
1413
backend_url: Optional[str] = None
1514
service_name: str = "value-control-agent"
1615
enable_console_export: bool = False
1716

18-
def __post_init__(self) -> None:
19-
pass
20-
2117

2218
def load_config_from_env() -> SDKConfig:
2319
"""Load SDK configuration from environment variables."""
2420
return SDKConfig(
25-
secret=os.getenv("VALUE_AGENT_SECRET", ""),
2621
otel_endpoint=os.getenv("VALUE_OTEL_ENDPOINT", "http://localhost:4317"),
2722
backend_url=os.getenv("VALUE_BACKEND_URL"),
2823
service_name=os.getenv("VALUE_SERVICE_NAME", "value-control-agent"),

0 commit comments

Comments
 (0)