agentspend-sdk 0.1.0__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.
Files changed (76) hide show
  1. agentspend_sdk-0.1.0/.gitignore +35 -0
  2. agentspend_sdk-0.1.0/PKG-INFO +131 -0
  3. agentspend_sdk-0.1.0/README.md +107 -0
  4. agentspend_sdk-0.1.0/dashboard/.gitignore +41 -0
  5. agentspend_sdk-0.1.0/dashboard/README.md +36 -0
  6. agentspend_sdk-0.1.0/dashboard/eslint.config.mjs +18 -0
  7. agentspend_sdk-0.1.0/dashboard/next-env.d.ts +6 -0
  8. agentspend_sdk-0.1.0/dashboard/next.config.ts +14 -0
  9. agentspend_sdk-0.1.0/dashboard/package-lock.json +6592 -0
  10. agentspend_sdk-0.1.0/dashboard/package.json +26 -0
  11. agentspend_sdk-0.1.0/dashboard/postcss.config.mjs +7 -0
  12. agentspend_sdk-0.1.0/dashboard/public/file.svg +1 -0
  13. agentspend_sdk-0.1.0/dashboard/public/globe.svg +1 -0
  14. agentspend_sdk-0.1.0/dashboard/public/next.svg +1 -0
  15. agentspend_sdk-0.1.0/dashboard/public/vercel.svg +1 -0
  16. agentspend_sdk-0.1.0/dashboard/public/window.svg +1 -0
  17. agentspend_sdk-0.1.0/dashboard/src/app/favicon.ico +0 -0
  18. agentspend_sdk-0.1.0/dashboard/src/app/globals.css +44 -0
  19. agentspend_sdk-0.1.0/dashboard/src/app/layout.tsx +43 -0
  20. agentspend_sdk-0.1.0/dashboard/src/app/page.tsx +326 -0
  21. agentspend_sdk-0.1.0/dashboard/tsconfig.json +34 -0
  22. agentspend_sdk-0.1.0/examples/agent_routing_demo.py +60 -0
  23. agentspend_sdk-0.1.0/examples/custom_policy_demo.py +72 -0
  24. agentspend_sdk-0.1.0/examples/framework_agnostic_integration.py +105 -0
  25. agentspend_sdk-0.1.0/pyproject.toml +72 -0
  26. agentspend_sdk-0.1.0/scripts/summarize_telemetry.py +106 -0
  27. agentspend_sdk-0.1.0/src/token_aud/__init__.py +3 -0
  28. agentspend_sdk-0.1.0/src/token_aud/agent/__init__.py +41 -0
  29. agentspend_sdk-0.1.0/src/token_aud/agent/adaptive.py +228 -0
  30. agentspend_sdk-0.1.0/src/token_aud/agent/loop_guard.py +102 -0
  31. agentspend_sdk-0.1.0/src/token_aud/agent/policy.py +163 -0
  32. agentspend_sdk-0.1.0/src/token_aud/agent/router.py +253 -0
  33. agentspend_sdk-0.1.0/src/token_aud/agent/runtime.py +358 -0
  34. agentspend_sdk-0.1.0/src/token_aud/agent/step_classifier.py +61 -0
  35. agentspend_sdk-0.1.0/src/token_aud/agent/telemetry.py +155 -0
  36. agentspend_sdk-0.1.0/src/token_aud/api/__init__.py +0 -0
  37. agentspend_sdk-0.1.0/src/token_aud/api/app.py +149 -0
  38. agentspend_sdk-0.1.0/src/token_aud/api/routes/__init__.py +0 -0
  39. agentspend_sdk-0.1.0/src/token_aud/api/serve.py +12 -0
  40. agentspend_sdk-0.1.0/src/token_aud/cli/__init__.py +0 -0
  41. agentspend_sdk-0.1.0/src/token_aud/cli/analyze.py +213 -0
  42. agentspend_sdk-0.1.0/src/token_aud/cli/configure.py +113 -0
  43. agentspend_sdk-0.1.0/src/token_aud/cli/main.py +24 -0
  44. agentspend_sdk-0.1.0/src/token_aud/config.py +42 -0
  45. agentspend_sdk-0.1.0/src/token_aud/core/__init__.py +0 -0
  46. agentspend_sdk-0.1.0/src/token_aud/core/auditor.py +325 -0
  47. agentspend_sdk-0.1.0/src/token_aud/core/judge.py +204 -0
  48. agentspend_sdk-0.1.0/src/token_aud/core/pricing.py +139 -0
  49. agentspend_sdk-0.1.0/src/token_aud/core/sampler.py +312 -0
  50. agentspend_sdk-0.1.0/src/token_aud/core/savings.py +286 -0
  51. agentspend_sdk-0.1.0/src/token_aud/data/__init__.py +0 -0
  52. agentspend_sdk-0.1.0/src/token_aud/data/default_routing_policy.yaml +185 -0
  53. agentspend_sdk-0.1.0/src/token_aud/data/pricing.json +349 -0
  54. agentspend_sdk-0.1.0/src/token_aud/db/__init__.py +0 -0
  55. agentspend_sdk-0.1.0/src/token_aud/db/session.py +31 -0
  56. agentspend_sdk-0.1.0/src/token_aud/models/__init__.py +0 -0
  57. agentspend_sdk-0.1.0/src/token_aud/models/db.py +77 -0
  58. agentspend_sdk-0.1.0/src/token_aud/models/schemas.py +99 -0
  59. agentspend_sdk-0.1.0/src/token_aud/parsers/__init__.py +10 -0
  60. agentspend_sdk-0.1.0/src/token_aud/parsers/anthropic.py +50 -0
  61. agentspend_sdk-0.1.0/src/token_aud/parsers/base.py +198 -0
  62. agentspend_sdk-0.1.0/src/token_aud/parsers/generic_csv.py +43 -0
  63. agentspend_sdk-0.1.0/src/token_aud/parsers/openai.py +50 -0
  64. agentspend_sdk-0.1.0/src/token_aud/reports/__init__.py +6 -0
  65. agentspend_sdk-0.1.0/src/token_aud/reports/html.py +219 -0
  66. agentspend_sdk-0.1.0/src/token_aud/reports/terminal.py +118 -0
  67. agentspend_sdk-0.1.0/tests/__init__.py +0 -0
  68. agentspend_sdk-0.1.0/tests/agent/__init__.py +0 -0
  69. agentspend_sdk-0.1.0/tests/agent/test_adaptive.py +115 -0
  70. agentspend_sdk-0.1.0/tests/agent/test_loop_guard.py +87 -0
  71. agentspend_sdk-0.1.0/tests/agent/test_policy.py +136 -0
  72. agentspend_sdk-0.1.0/tests/agent/test_router.py +213 -0
  73. agentspend_sdk-0.1.0/tests/agent/test_runtime.py +182 -0
  74. agentspend_sdk-0.1.0/tests/agent/test_step_classifier.py +53 -0
  75. agentspend_sdk-0.1.0/tests/agent/test_telemetry.py +107 -0
  76. agentspend_sdk-0.1.0/uv.lock +2310 -0
@@ -0,0 +1,35 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+
8
+ # Virtual environment
9
+ .venv/
10
+
11
+ # IDE
12
+ .vscode/
13
+ .idea/
14
+
15
+ # OS
16
+ .DS_Store
17
+
18
+ # Environment
19
+ .env
20
+ .env.local
21
+
22
+ # Database
23
+ *.db
24
+ *.sqlite3
25
+
26
+ # Reports output
27
+ reports_output/
28
+
29
+ # Dashboard
30
+ dashboard/node_modules/
31
+ dashboard/.next/
32
+
33
+ #testing files
34
+ test_pipeline.py
35
+ sample_data.csv
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentspend-sdk
3
+ Version: 0.1.0
4
+ Summary: AgentSpend — runtime cost optimizer for AI agents. Route LLM calls to the cheapest capable model with fallbacks, loop guards, and telemetry.
5
+ Requires-Python: <3.14,>=3.12
6
+ Requires-Dist: aiosqlite>=0.20
7
+ Requires-Dist: alembic>=1.14
8
+ Requires-Dist: fastapi>=0.115
9
+ Requires-Dist: google-auth>=2.48.0
10
+ Requires-Dist: google-cloud-aiplatform>=1.139.0
11
+ Requires-Dist: litellm>=1.50
12
+ Requires-Dist: pandas>=2.2
13
+ Requires-Dist: pydantic-settings>=2.0
14
+ Requires-Dist: pydantic>=2.0
15
+ Requires-Dist: python-multipart>=0.0.9
16
+ Requires-Dist: pyyaml>=6.0
17
+ Requires-Dist: rich>=13.0
18
+ Requires-Dist: sqlalchemy>=2.0
19
+ Requires-Dist: typer>=0.15
20
+ Requires-Dist: uvicorn[standard]>=0.32
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=9.0; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # token-aud
26
+
27
+ AI cost optimization toolkit for LLM workloads.
28
+
29
+ `token-aud` now includes two complementary workflows:
30
+
31
+ - **Audit mode (CLI/API):** Analyze historical usage logs and estimate savings opportunities with Student-Teacher-Judge sampling.
32
+ - **AgentSpend SDK:** Route live agent steps (`plan`, `reason`, `tool`, `verify`, `draft`, `summarize`) to cost/quality-appropriate models with fallbacks, loop guards, and telemetry.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ uv sync --no-editable
38
+ ```
39
+
40
+ For local development tooling (tests):
41
+
42
+ ```bash
43
+ uv sync --no-editable --extra dev
44
+ ```
45
+
46
+ ## Quick Start (AgentSpend)
47
+
48
+ Run these three commands from repo root:
49
+
50
+ ```bash
51
+ uv sync --no-editable --extra dev
52
+ uv run --no-sync python -m pytest tests/agent -q
53
+ uv run --no-sync python examples/agent_routing_demo.py
54
+ ```
55
+
56
+ Expected results:
57
+
58
+ - Agent tests pass.
59
+ - Demo prints routed step decisions, per-step telemetry, and total run cost.
60
+ - `agent_telemetry.jsonl` is generated locally.
61
+
62
+ ## AgentSpend Usage
63
+
64
+ ### 1) Default policy
65
+
66
+ ```python
67
+ from token_aud.agent import AgentSpend
68
+
69
+ agent = AgentSpend.default()
70
+ result = agent.route_call(
71
+ step="plan",
72
+ messages=[{"role": "user", "content": "Break this task into a plan"}],
73
+ )
74
+
75
+ print(result.model_used, result.cost_usd, result.content)
76
+ ```
77
+
78
+ ### 2) Custom policy YAML
79
+
80
+ ```python
81
+ from token_aud.agent import AgentSpend
82
+
83
+ agent = AgentSpend.from_yaml("routing_policy.yaml")
84
+ result = agent.route_call(
85
+ step="reason",
86
+ messages=[{"role": "user", "content": "Compare two architectures"}],
87
+ )
88
+
89
+ print(result.model_used, result.fallbacks_tried)
90
+ ```
91
+
92
+ Built-in default policy path:
93
+
94
+ - `src/token_aud/data/default_routing_policy.yaml`
95
+
96
+ ## AgentSpend Core Components
97
+
98
+ - `src/token_aud/agent/policy.py`: Pydantic policy schema + YAML loading
99
+ - `src/token_aud/agent/router.py`: deterministic model selection
100
+ - `src/token_aud/agent/runtime.py`: `route_call()` execution + fallbacks
101
+ - `src/token_aud/agent/loop_guard.py`: repeated-turn loop detection
102
+ - `src/token_aud/agent/telemetry.py`: JSONL/HTTP telemetry sinks
103
+ - `src/token_aud/agent/adaptive.py`: optional adaptive routing layer
104
+
105
+ ## AgentSpend Examples
106
+
107
+ - `examples/agent_routing_demo.py`: end-to-end routed run with telemetry
108
+ - `examples/custom_policy_demo.py`: loop escalation and hard-stop behavior
109
+ - `examples/framework_agnostic_integration.py`: generic agent-loop integration with explicit success feedback
110
+ - `scripts/summarize_telemetry.py`: convert `agent_telemetry.jsonl` into cost/fallback/latency summary
111
+
112
+ ```bash
113
+ uv run --no-sync python scripts/summarize_telemetry.py agent_telemetry.jsonl
114
+ ```
115
+
116
+ ## Audit CLI (legacy + still supported)
117
+
118
+ ```bash
119
+ uv run --no-sync token-aud --help
120
+ uv run --no-sync token-aud analyze sample_data.csv --dry-run
121
+ ```
122
+
123
+ ## Environment Variables
124
+
125
+ Common provider credentials:
126
+
127
+ - `OPENAI_API_KEY`
128
+ - `ANTHROPIC_API_KEY`
129
+ - `GEMINI_API_KEY` or `GOOGLE_API_KEY` (depending on provider path)
130
+
131
+ For Google Vertex flows, ensure ADC is configured (`gcloud auth application-default login`).
@@ -0,0 +1,107 @@
1
+ # token-aud
2
+
3
+ AI cost optimization toolkit for LLM workloads.
4
+
5
+ `token-aud` now includes two complementary workflows:
6
+
7
+ - **Audit mode (CLI/API):** Analyze historical usage logs and estimate savings opportunities with Student-Teacher-Judge sampling.
8
+ - **AgentSpend SDK:** Route live agent steps (`plan`, `reason`, `tool`, `verify`, `draft`, `summarize`) to cost/quality-appropriate models with fallbacks, loop guards, and telemetry.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ uv sync --no-editable
14
+ ```
15
+
16
+ For local development tooling (tests):
17
+
18
+ ```bash
19
+ uv sync --no-editable --extra dev
20
+ ```
21
+
22
+ ## Quick Start (AgentSpend)
23
+
24
+ Run these three commands from repo root:
25
+
26
+ ```bash
27
+ uv sync --no-editable --extra dev
28
+ uv run --no-sync python -m pytest tests/agent -q
29
+ uv run --no-sync python examples/agent_routing_demo.py
30
+ ```
31
+
32
+ Expected results:
33
+
34
+ - Agent tests pass.
35
+ - Demo prints routed step decisions, per-step telemetry, and total run cost.
36
+ - `agent_telemetry.jsonl` is generated locally.
37
+
38
+ ## AgentSpend Usage
39
+
40
+ ### 1) Default policy
41
+
42
+ ```python
43
+ from token_aud.agent import AgentSpend
44
+
45
+ agent = AgentSpend.default()
46
+ result = agent.route_call(
47
+ step="plan",
48
+ messages=[{"role": "user", "content": "Break this task into a plan"}],
49
+ )
50
+
51
+ print(result.model_used, result.cost_usd, result.content)
52
+ ```
53
+
54
+ ### 2) Custom policy YAML
55
+
56
+ ```python
57
+ from token_aud.agent import AgentSpend
58
+
59
+ agent = AgentSpend.from_yaml("routing_policy.yaml")
60
+ result = agent.route_call(
61
+ step="reason",
62
+ messages=[{"role": "user", "content": "Compare two architectures"}],
63
+ )
64
+
65
+ print(result.model_used, result.fallbacks_tried)
66
+ ```
67
+
68
+ Built-in default policy path:
69
+
70
+ - `src/token_aud/data/default_routing_policy.yaml`
71
+
72
+ ## AgentSpend Core Components
73
+
74
+ - `src/token_aud/agent/policy.py`: Pydantic policy schema + YAML loading
75
+ - `src/token_aud/agent/router.py`: deterministic model selection
76
+ - `src/token_aud/agent/runtime.py`: `route_call()` execution + fallbacks
77
+ - `src/token_aud/agent/loop_guard.py`: repeated-turn loop detection
78
+ - `src/token_aud/agent/telemetry.py`: JSONL/HTTP telemetry sinks
79
+ - `src/token_aud/agent/adaptive.py`: optional adaptive routing layer
80
+
81
+ ## AgentSpend Examples
82
+
83
+ - `examples/agent_routing_demo.py`: end-to-end routed run with telemetry
84
+ - `examples/custom_policy_demo.py`: loop escalation and hard-stop behavior
85
+ - `examples/framework_agnostic_integration.py`: generic agent-loop integration with explicit success feedback
86
+ - `scripts/summarize_telemetry.py`: convert `agent_telemetry.jsonl` into cost/fallback/latency summary
87
+
88
+ ```bash
89
+ uv run --no-sync python scripts/summarize_telemetry.py agent_telemetry.jsonl
90
+ ```
91
+
92
+ ## Audit CLI (legacy + still supported)
93
+
94
+ ```bash
95
+ uv run --no-sync token-aud --help
96
+ uv run --no-sync token-aud analyze sample_data.csv --dry-run
97
+ ```
98
+
99
+ ## Environment Variables
100
+
101
+ Common provider credentials:
102
+
103
+ - `OPENAI_API_KEY`
104
+ - `ANTHROPIC_API_KEY`
105
+ - `GEMINI_API_KEY` or `GOOGLE_API_KEY` (depending on provider path)
106
+
107
+ For Google Vertex flows, ensure ADC is configured (`gcloud auth application-default login`).
@@ -0,0 +1,41 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # production
21
+ /build
22
+
23
+ # misc
24
+ .DS_Store
25
+ *.pem
26
+
27
+ # debug
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ .pnpm-debug.log*
32
+
33
+ # env files (can opt-in for committing if needed)
34
+ .env*
35
+
36
+ # vercel
37
+ .vercel
38
+
39
+ # typescript
40
+ *.tsbuildinfo
41
+ next-env.d.ts
@@ -0,0 +1,36 @@
1
+ This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2
+
3
+ ## Getting Started
4
+
5
+ First, run the development server:
6
+
7
+ ```bash
8
+ npm run dev
9
+ # or
10
+ yarn dev
11
+ # or
12
+ pnpm dev
13
+ # or
14
+ bun dev
15
+ ```
16
+
17
+ Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18
+
19
+ You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20
+
21
+ This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22
+
23
+ ## Learn More
24
+
25
+ To learn more about Next.js, take a look at the following resources:
26
+
27
+ - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28
+ - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29
+
30
+ You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31
+
32
+ ## Deploy on Vercel
33
+
34
+ The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35
+
36
+ Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
@@ -0,0 +1,18 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import nextVitals from "eslint-config-next/core-web-vitals";
3
+ import nextTs from "eslint-config-next/typescript";
4
+
5
+ const eslintConfig = defineConfig([
6
+ ...nextVitals,
7
+ ...nextTs,
8
+ // Override default ignores of eslint-config-next.
9
+ globalIgnores([
10
+ // Default ignores of eslint-config-next:
11
+ ".next/**",
12
+ "out/**",
13
+ "build/**",
14
+ "next-env.d.ts",
15
+ ]),
16
+ ]);
17
+
18
+ export default eslintConfig;
@@ -0,0 +1,6 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+ import "./.next/dev/types/routes.d.ts";
4
+
5
+ // NOTE: This file should not be edited
6
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -0,0 +1,14 @@
1
+ import type { NextConfig } from "next";
2
+
3
+ const nextConfig: NextConfig = {
4
+ async rewrites() {
5
+ return [
6
+ {
7
+ source: "/api/:path*",
8
+ destination: "http://localhost:8000/api/:path*",
9
+ },
10
+ ];
11
+ },
12
+ };
13
+
14
+ export default nextConfig;