agentcogs 0.2.1__tar.gz → 0.2.2__tar.gz
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.
- {agentcogs-0.2.1 → agentcogs-0.2.2}/.gitignore +3 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/PKG-INFO +10 -6
- {agentcogs-0.2.1 → agentcogs-0.2.2}/PYPI.md +9 -5
- agentcogs-0.2.2/src/agentcogs/_version.py +1 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/budget.py +12 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/config.py +9 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/localstore.py +44 -0
- agentcogs-0.2.1/src/agentcogs/_version.py +0 -1
- {agentcogs-0.2.1 → agentcogs-0.2.2}/LICENSE +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/pyproject.toml +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/__init__.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/__main__.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/_shekel_compat.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/assistant.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/cli.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/client.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/context.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/data/price_book_fixture_v1.json +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/errors.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/instrument.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/integrations/__init__.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/integrations/fastapi.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/integrations/langgraph.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/integrations/litellm_event.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/kernel/__init__.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/kernel/attribute.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/kernel/money.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/localhttp.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/outbox.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/ping.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/provider_watch.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/reports.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/shutdown.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/star.py +0 -0
- {agentcogs-0.2.1 → agentcogs-0.2.2}/src/agentcogs/tokens.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: agentcogs
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Customer-level AI unit economics. Compare each customer's LLM cost with their monthly fee
|
|
5
5
|
Project-URL: Homepage, https://agentcogs.vercel.app
|
|
6
6
|
Project-URL: Repository, https://github.com/vaibhav11123/agentcogs
|
|
@@ -39,9 +39,13 @@ AgentCOGS is an open-source Python SDK and a self-hosted dashboard for customer-
|
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
41
|
pip install agentcogs
|
|
42
|
+
agentcogs init
|
|
43
|
+
agentcogs status
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
`init` records one sample for `customer_001` at $0.0246 and leaves enforcement off. It does not call a model. With no API key, a later call inside `run(customer_id=...)` is priced from the response and stored in that same file. `instrument()` does not write a row. No prompt or provider key is written.
|
|
47
|
+
|
|
48
|
+
This package is the SDK. The customer list is the dashboard in the [repository](https://github.com/vaibhav11123/agentcogs), and you run that yourself. A hosted API is not serving. The working sample is [agentcogs.vercel.app](https://agentcogs.vercel.app).
|
|
45
49
|
|
|
46
50
|
## What does the number mean?
|
|
47
51
|
|
|
@@ -71,17 +75,17 @@ with agentcogs.run(workflow_id="support") as ctx:
|
|
|
71
75
|
print(ctx.wait_for_ingest().accepted, ctx.run_id)
|
|
72
76
|
```
|
|
73
77
|
|
|
74
|
-
The SDK does not call a model. Inside the block,
|
|
78
|
+
The SDK does not call a model. Inside the block, an OpenAI or Anthropic call is read from the response. Cached tokens and cache writes are part of the posted total. With no provider call, the same block posts a zero-cost run so you can see the row. Open that customer and type the monthly fee.
|
|
75
79
|
|
|
76
80
|
`python examples/hello_agentcogs.py` in the repository is this path. `python examples/one_run.py` posts one recorded cost of USD 0.84 and does not call a model.
|
|
77
81
|
|
|
78
82
|
## How attribution works
|
|
79
83
|
|
|
80
|
-
`set_customer()` names the tenant for this request. `run()` watches the instrumented client calls in the block and posts one event with `total_usd` when the block exits. If no customer is set, `run()` raises before the block. A duplicate `run_id` is accepted as a duplicate and is not stored twice. A failed post sits in a local outbox and is retried. `python -m agentcogs outbox status` shows what has not been delivered.
|
|
84
|
+
`set_customer()` names the tenant for this request. `run()` watches the instrumented client calls in the block and posts one event with `total_usd` when the block exits. If no customer is set, `run()` raises before the block. A duplicate `run_id` is accepted as a duplicate and is not stored twice. On the self-hosted API, that duplicate keeps the customer stored on the first commit. A failed post sits in a local outbox and is retried. `python -m agentcogs outbox status` shows what has not been delivered.
|
|
81
85
|
|
|
82
86
|
## What the budget check does
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
Enforcement stays off until the workspace turns it on. While it is off, an exceeded `monthly_budget_usd` does not stop the next `run()`. When the workspace turns enforcement on, an exceeded budget raises `CustomerBudgetExceededError` and does not enter the block. Two calls already in flight can both pass. It is not an atomic reservation. A LiteLLM callback records cost after the provider has already answered, so it cannot stop that call.
|
|
85
89
|
|
|
86
90
|
LiteLLM does not ship the callback. You copy it from the repository. The FastAPI middleware is a separate extra: `pip install "agentcogs[integrations]"`.
|
|
87
91
|
|
|
@@ -89,7 +93,7 @@ LiteLLM does not ship the callback. You copy it from the repository. The FastAPI
|
|
|
89
93
|
|
|
90
94
|
| | |
|
|
91
95
|
| --- | --- |
|
|
92
|
-
| OpenAI and Anthropic | Usage
|
|
96
|
+
| OpenAI and Anthropic | Usage on the response inside `run()`, including cached tokens and cache writes |
|
|
93
97
|
| [FastAPI](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/fastapi.md) | Set the tenant from the request. Needs the `integrations` extra |
|
|
94
98
|
| [LangGraph](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/langgraph.md) | Wrap the graph |
|
|
95
99
|
| [LiteLLM](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/litellm.md) | A callback you register. It posts after the proxy call |
|
|
@@ -8,9 +8,13 @@ AgentCOGS is an open-source Python SDK and a self-hosted dashboard for customer-
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pip install agentcogs
|
|
11
|
+
agentcogs init
|
|
12
|
+
agentcogs status
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
`init` records one sample for `customer_001` at $0.0246 and leaves enforcement off. It does not call a model. With no API key, a later call inside `run(customer_id=...)` is priced from the response and stored in that same file. `instrument()` does not write a row. No prompt or provider key is written.
|
|
16
|
+
|
|
17
|
+
This package is the SDK. The customer list is the dashboard in the [repository](https://github.com/vaibhav11123/agentcogs), and you run that yourself. A hosted API is not serving. The working sample is [agentcogs.vercel.app](https://agentcogs.vercel.app).
|
|
14
18
|
|
|
15
19
|
## What does the number mean?
|
|
16
20
|
|
|
@@ -40,17 +44,17 @@ with agentcogs.run(workflow_id="support") as ctx:
|
|
|
40
44
|
print(ctx.wait_for_ingest().accepted, ctx.run_id)
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
The SDK does not call a model. Inside the block,
|
|
47
|
+
The SDK does not call a model. Inside the block, an OpenAI or Anthropic call is read from the response. Cached tokens and cache writes are part of the posted total. With no provider call, the same block posts a zero-cost run so you can see the row. Open that customer and type the monthly fee.
|
|
44
48
|
|
|
45
49
|
`python examples/hello_agentcogs.py` in the repository is this path. `python examples/one_run.py` posts one recorded cost of USD 0.84 and does not call a model.
|
|
46
50
|
|
|
47
51
|
## How attribution works
|
|
48
52
|
|
|
49
|
-
`set_customer()` names the tenant for this request. `run()` watches the instrumented client calls in the block and posts one event with `total_usd` when the block exits. If no customer is set, `run()` raises before the block. A duplicate `run_id` is accepted as a duplicate and is not stored twice. A failed post sits in a local outbox and is retried. `python -m agentcogs outbox status` shows what has not been delivered.
|
|
53
|
+
`set_customer()` names the tenant for this request. `run()` watches the instrumented client calls in the block and posts one event with `total_usd` when the block exits. If no customer is set, `run()` raises before the block. A duplicate `run_id` is accepted as a duplicate and is not stored twice. On the self-hosted API, that duplicate keeps the customer stored on the first commit. A failed post sits in a local outbox and is retried. `python -m agentcogs outbox status` shows what has not been delivered.
|
|
50
54
|
|
|
51
55
|
## What the budget check does
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
Enforcement stays off until the workspace turns it on. While it is off, an exceeded `monthly_budget_usd` does not stop the next `run()`. When the workspace turns enforcement on, an exceeded budget raises `CustomerBudgetExceededError` and does not enter the block. Two calls already in flight can both pass. It is not an atomic reservation. A LiteLLM callback records cost after the provider has already answered, so it cannot stop that call.
|
|
54
58
|
|
|
55
59
|
LiteLLM does not ship the callback. You copy it from the repository. The FastAPI middleware is a separate extra: `pip install "agentcogs[integrations]"`.
|
|
56
60
|
|
|
@@ -58,7 +62,7 @@ LiteLLM does not ship the callback. You copy it from the repository. The FastAPI
|
|
|
58
62
|
|
|
59
63
|
| | |
|
|
60
64
|
| --- | --- |
|
|
61
|
-
| OpenAI and Anthropic | Usage
|
|
65
|
+
| OpenAI and Anthropic | Usage on the response inside `run()`, including cached tokens and cache writes |
|
|
62
66
|
| [FastAPI](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/fastapi.md) | Set the tenant from the request. Needs the `integrations` extra |
|
|
63
67
|
| [LangGraph](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/langgraph.md) | Wrap the graph |
|
|
64
68
|
| [LiteLLM](https://github.com/vaibhav11123/agentcogs/blob/main/docs/integrations/litellm.md) | A callback you register. It posts after the proxy call |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.2"
|
|
@@ -12,6 +12,7 @@ from .client import emit_event, emit_event_sync, fetch_budget
|
|
|
12
12
|
from .config import get_config
|
|
13
13
|
from .context import resolve_customer, resolve_workflow
|
|
14
14
|
from .errors import ConfigurationError, CustomerBudgetExceededError
|
|
15
|
+
from .localstore import ledger_home, record_calls
|
|
15
16
|
from .provider_watch import pop as pop_watch, priced_calls, push as push_watch, snapshot
|
|
16
17
|
|
|
17
18
|
log = logging.getLogger("agentcogs")
|
|
@@ -161,6 +162,17 @@ def run(
|
|
|
161
162
|
if run_ctx is not None:
|
|
162
163
|
run_ctx._event = event
|
|
163
164
|
emit_event(event)
|
|
165
|
+
home = ledger_home()
|
|
166
|
+
if cfg.offline and home is not None and status == "completed" and priced is not None:
|
|
167
|
+
record_calls(
|
|
168
|
+
home,
|
|
169
|
+
run_id=run_id,
|
|
170
|
+
customer_id=resolved_customer,
|
|
171
|
+
workflow=resolved_workflow,
|
|
172
|
+
calls=priced["calls"],
|
|
173
|
+
)
|
|
174
|
+
except ValueError:
|
|
175
|
+
raise
|
|
164
176
|
except Exception as e:
|
|
165
177
|
log.warning("telemetry failed", exc_info=True)
|
|
166
178
|
cb = cfg.on_telemetry_error
|
|
@@ -86,6 +86,15 @@ def init(
|
|
|
86
86
|
|
|
87
87
|
def get_config() -> _Config:
|
|
88
88
|
if _config.api_key is None and not _config.offline:
|
|
89
|
+
if os.environ.get("AGENTCOGS_API_KEY"):
|
|
90
|
+
init()
|
|
91
|
+
return _config
|
|
92
|
+
from .localstore import ledger_home
|
|
93
|
+
|
|
94
|
+
if ledger_home() is not None:
|
|
95
|
+
_config.offline = True
|
|
96
|
+
_config.workspace_id = _config.workspace_id or "ws_local"
|
|
97
|
+
return _config
|
|
89
98
|
init()
|
|
90
99
|
return _config
|
|
91
100
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import os
|
|
6
7
|
import secrets
|
|
7
8
|
import shutil
|
|
8
9
|
import sqlite3
|
|
@@ -52,6 +53,15 @@ def fixture_case() -> dict:
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
|
|
56
|
+
def ledger_home() -> Path | None:
|
|
57
|
+
"""The ledger from `agentcogs init`, if this process can see it."""
|
|
58
|
+
raw = os.environ.get("AGENTCOGS_HOME")
|
|
59
|
+
home = Path(raw) if raw else Path.cwd() / ".agentcogs"
|
|
60
|
+
if (home / "ledger.sqlite").is_file():
|
|
61
|
+
return home
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
|
|
55
65
|
def connect(home: Path) -> sqlite3.Connection:
|
|
56
66
|
home.mkdir(parents=True, exist_ok=True)
|
|
57
67
|
conn = sqlite3.connect(home / "ledger.sqlite", isolation_level=None)
|
|
@@ -236,6 +246,40 @@ def record_event(
|
|
|
236
246
|
return {"duplicate": False, "incurred_micro": incurred, "enforce": enforce}
|
|
237
247
|
|
|
238
248
|
|
|
249
|
+
def record_calls(
|
|
250
|
+
home: Path,
|
|
251
|
+
*,
|
|
252
|
+
run_id: str,
|
|
253
|
+
customer_id: str,
|
|
254
|
+
workflow: str,
|
|
255
|
+
calls: list[dict],
|
|
256
|
+
) -> list[dict]:
|
|
257
|
+
"""Store priced calls from this process. One row per call. No prompt is read."""
|
|
258
|
+
if not calls:
|
|
259
|
+
return []
|
|
260
|
+
conn = connect(home)
|
|
261
|
+
try:
|
|
262
|
+
written: list[dict] = []
|
|
263
|
+
many = len(calls) > 1
|
|
264
|
+
for call in calls:
|
|
265
|
+
model = str(call.get("model") or "")
|
|
266
|
+
call_id = str(call.get("call_id") or "c0")
|
|
267
|
+
provider = "Anthropic" if model.startswith("claude") else "OpenAI"
|
|
268
|
+
result = record_event(
|
|
269
|
+
conn,
|
|
270
|
+
run_id=f"{run_id}:{call_id}" if many else run_id,
|
|
271
|
+
customer_id=customer_id,
|
|
272
|
+
provider=provider,
|
|
273
|
+
workflow=workflow,
|
|
274
|
+
model=model,
|
|
275
|
+
case={"calls": [{"call_id": call_id, "lanes": call.get("lanes") or {}}], "segments": []},
|
|
276
|
+
)
|
|
277
|
+
written.append(result)
|
|
278
|
+
return written
|
|
279
|
+
finally:
|
|
280
|
+
conn.close()
|
|
281
|
+
|
|
282
|
+
|
|
239
283
|
def verify_fixture(home: Path) -> dict:
|
|
240
284
|
"""Price the documented sample call locally. No provider request."""
|
|
241
285
|
conn = connect(home)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|