agentforge-oss 0.5.0__tar.gz → 0.5.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.
Files changed (96) hide show
  1. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/.gitignore +3 -0
  2. agentforge_oss-0.5.2/CHANGELOG.md +93 -0
  3. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/LICENSE +1 -1
  4. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/PKG-INFO +16 -6
  5. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/README.md +4 -3
  6. agentforge_oss-0.5.2/docs/examples/custom-tools.md +70 -0
  7. agentforge_oss-0.5.2/docs/examples/index.md +18 -0
  8. agentforge_oss-0.5.2/docs/examples/otel-tracing.md +98 -0
  9. agentforge_oss-0.5.2/docs/examples/parallel-supervisor.md +66 -0
  10. agentforge_oss-0.5.2/docs/examples/persistent-rag.md +69 -0
  11. agentforge_oss-0.5.2/docs/examples/policy-governance.md +128 -0
  12. agentforge_oss-0.5.2/examples/rag_pgvector.py +46 -0
  13. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/__init__.py +2 -0
  14. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/_version.py +1 -1
  15. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/config.py +5 -1
  16. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/memory/__init__.py +12 -0
  17. agentforge_oss-0.5.2/forge/memory/pgvector.py +162 -0
  18. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/observability/events.py +4 -3
  19. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/builtin/http.py +9 -1
  20. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/pyproject.toml +17 -4
  21. agentforge_oss-0.5.2/tests/test_pgvector_memory.py +190 -0
  22. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/enterprise_governance.py +0 -0
  23. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/otel_tracing.py +0 -0
  24. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/policy_governance.py +0 -0
  25. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/quickstart.py +0 -0
  26. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/rag.py +0 -0
  27. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/rag_persistent.py +0 -0
  28. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/examples/tool_use.py +0 -0
  29. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/agents/__init__.py +0 -0
  30. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/agents/agent.py +0 -0
  31. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/agents/base.py +0 -0
  32. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/agents/supervisor.py +0 -0
  33. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/cli/__init__.py +0 -0
  34. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/cli/console.py +0 -0
  35. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/cli/main.py +0 -0
  36. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/compliance/__init__.py +0 -0
  37. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/compliance/audit.py +0 -0
  38. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/compliance/redaction.py +0 -0
  39. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/exceptions.py +0 -0
  40. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/governance/__init__.py +0 -0
  41. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/governance/policy.py +0 -0
  42. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/memory/base.py +0 -0
  43. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/memory/conversation.py +0 -0
  44. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/memory/sqlite.py +0 -0
  45. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/memory/vector.py +0 -0
  46. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/__init__.py +0 -0
  47. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/base.py +0 -0
  48. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/__init__.py +0 -0
  49. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/anthropic.py +0 -0
  50. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/bedrock.py +0 -0
  51. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/echo.py +0 -0
  52. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/ollama.py +0 -0
  53. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/providers/openai.py +0 -0
  54. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/registry.py +0 -0
  55. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/models/router.py +0 -0
  56. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/observability/__init__.py +0 -0
  57. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/observability/logging.py +0 -0
  58. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/observability/otel.py +0 -0
  59. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/observability/usage.py +0 -0
  60. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/orchestration/__init__.py +0 -0
  61. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/orchestration/context.py +0 -0
  62. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/orchestration/orchestrator.py +0 -0
  63. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/py.typed +0 -0
  64. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/security/__init__.py +0 -0
  65. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/security/access.py +0 -0
  66. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/security/sandbox.py +0 -0
  67. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/security/sanitization.py +0 -0
  68. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/__init__.py +0 -0
  69. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/base.py +0 -0
  70. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/builtin/__init__.py +0 -0
  71. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/builtin/calculator.py +0 -0
  72. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/builtin/time.py +0 -0
  73. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/tools/registry.py +0 -0
  74. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/forge/types.py +0 -0
  75. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/conftest.py +0 -0
  76. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_agents.py +0 -0
  77. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_audit.py +0 -0
  78. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_audit_robustness.py +0 -0
  79. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_bedrock_provider.py +0 -0
  80. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_config_security.py +0 -0
  81. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_config_validation.py +0 -0
  82. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_http_security.py +0 -0
  83. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_memory.py +0 -0
  84. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_models.py +0 -0
  85. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_ollama_provider.py +0 -0
  86. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_openai_provider.py +0 -0
  87. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_orchestrator.py +0 -0
  88. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_otel.py +0 -0
  89. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_parallel_workers.py +0 -0
  90. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_policy_governance.py +0 -0
  91. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_security.py +0 -0
  92. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_sqlite_concurrency.py +0 -0
  93. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_sqlite_memory.py +0 -0
  94. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_streaming.py +0 -0
  95. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_tools.py +0 -0
  96. {agentforge_oss-0.5.0 → agentforge_oss-0.5.2}/tests/test_types.py +0 -0
@@ -70,6 +70,9 @@ htmlcov/
70
70
  coverage.xml
71
71
  .hypothesis/
72
72
 
73
+ # MkDocs build output
74
+ site/
75
+
73
76
  # ---------------------------------------------------------------------------
74
77
  # Editors / OS
75
78
  # ---------------------------------------------------------------------------
@@ -0,0 +1,93 @@
1
+ # Changelog
2
+
3
+ All notable changes to Forge are documented here.
4
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5
+ Versioning follows [Semantic Versioning](https://semver.org/).
6
+
7
+ ---
8
+
9
+ ## [Unreleased]
10
+
11
+ ### Maintenance
12
+ - Consolidated git commit authorship under a single maintainer identity (`sekacorn`).
13
+
14
+ ## [0.5.2] — 2026-07-07
15
+
16
+ ### Release infrastructure
17
+ - Reconnected release metadata for the recreated `sekacorn/AgentForge` repository.
18
+ - Updated package metadata to publish public author identity as `sekacorn`.
19
+ - Restored the dedicated GitHub Actions release workflow for PyPI Trusted Publishing.
20
+ - Added distribution validation and artifact handoff before publishing.
21
+
22
+ ### Documentation
23
+ - Replaced stale version-specific shipped-feature wording with current release language.
24
+
25
+ ## [0.5.1] — 2026-07-05
26
+
27
+ ### Added
28
+ - PGVectorMemoryStore: durable RAG backend using PostgreSQL + pgvector with IVFFlat ANN indexing (cosine distance), asyncpg connection pool
29
+ - FORGE_PGVECTOR_DSN config for PostgreSQL connection string
30
+ - New extra: `pip install "agentforge-oss[pgvector]"` (asyncpg + pgvector-python)
31
+ - New example: examples/rag_pgvector.py
32
+
33
+ ## [0.5.0] — 2026-07-01
34
+
35
+ ### Added
36
+ - Policy-as-code governance: PolicyRule, PolicySet, PolicyDecision -- define deny/approve/log rules evaluated before every tool call
37
+ - Human-in-the-loop approval gates: async approver callbacks pause execution for human sign-off
38
+ - Four new event types: POLICY_EVALUATED, POLICY_APPROVED, POLICY_DENIED, POLICY_LOGGED
39
+ - New example: examples/policy_governance.py
40
+
41
+ ## [0.4.0] — 2026-06-30
42
+
43
+ ### Added
44
+ - Amazon Bedrock provider: Claude 3.5 Haiku/Sonnet, Llama 3.1 70B/405B, Mistral Large via the unified Converse API
45
+ - Standard AWS credential chain (env vars, profile, IAM role) — no custom credential handling
46
+ - Native streaming via converse_stream()
47
+
48
+ ## [0.3.0] — 2026-06-29
49
+
50
+ ### Added
51
+ - Ollama provider: local LLM execution via Ollama REST API (llama3.2:3b, llama3.1:8b, llama3.1:70b, mistral:7b, qwen2.5:7b, deepseek-r1:8b) — zero cost, no API key, air-gap compatible
52
+ - Native streaming support in OllamaProvider (newline-delimited JSON stream)
53
+ - OLLAMA_BASE_URL configuration with automatic reachability detection
54
+ - SQLiteMemoryStore: persistent RAG backend using stdlib sqlite3 + aiosqlite, zero external vector extension required
55
+ - FORGE_MEMORY_BACKEND=sqlite config to enable persistence across restarts
56
+ - New example: examples/rag_persistent.py
57
+ - OpenTelemetry export: traces (forge.run, forge.agent, forge.model_call, forge.tool_call spans) and metrics (runs, duration, tokens, tool calls) via opentelemetry-sdk
58
+ - ConsoleSpanExporter by default (zero infra), OTLP endpoint for production
59
+ - FORGE_OTEL_ENABLED, FORGE_OTEL_ENDPOINT, FORGE_OTEL_SERVICE_NAME config
60
+ - New example: examples/otel_tracing.py
61
+
62
+ ## [0.2.0] — 2026-06-28
63
+
64
+ ### Added
65
+ - Parallel worker execution: the supervisor now runs workers concurrently with `asyncio.gather` in bounded batches (`max_workers`). A pre-flight budget cap refuses a batch before spawning if its worst-case spend would exceed the remaining budget, and a failing worker is isolated gracefully (emits `WORKER_FAILED`, returns a partial result) instead of cancelling its peers.
66
+ - Streaming token output through the event bus: `TOKEN_STREAM_START`, `TOKEN_CHUNK` (chunk plus running cumulative text), and `TOKEN_STREAM_END` events, enabled via `stream=True` on `Orchestrator.run()` and the `forge run --stream` CLI flag. `ModelProvider.stream()` ships a buffered default so every provider streams out of the box; `EchoProvider` streams natively offline.
67
+ - `WORKER_STARTED` and `WORKER_FAILED` lifecycle events (the event bus now exposes 21 event types, up from 16).
68
+ - Community health files: issue templates (bug report, feature request, provider request), a pull request template, and this changelog.
69
+
70
+ ### Changed
71
+ - README rewritten to reflect the shipped feature set, including a "What's shipped" status table covering parallel execution, streaming, and all three providers.
72
+ - Test suite expanded to 47 hermetic tests (from 38); `mypy --strict` and `ruff` remain clean.
73
+
74
+ ## [0.1.0] — 2026-06-28
75
+
76
+ ### Added
77
+ - Multi-agent orchestration: a supervisor decomposes a goal into subtasks, delegates to focused worker agents (sequential execution), and synthesizes the result.
78
+ - Intelligent model routing: cost_optimized, quality_first, balanced, fixed strategies.
79
+ - Anthropic provider: Claude Haiku 4.5, Sonnet 4.6, Opus 4.8, Fable 5.
80
+ - OpenAI provider: gpt-4o-mini, gpt-4o, gpt-4.1, o3.
81
+ - Offline deterministic Echo provider (zero config, no API key required).
82
+ - Tool sandboxing with allowlist/denylist, per-tool timeouts, dangerous-denied-by-default.
83
+ - RBAC with roles: admin, operator, developer, viewer.
84
+ - Prompt-injection heuristics and input sanitization.
85
+ - SHA-256 hash-chained tamper-evident audit log.
86
+ - PII redaction: emails, cards, SSNs, IPs, phones.
87
+ - Event bus with 16 lifecycle event types.
88
+ - Per-run cost reporting (tokens + USD, per model, per agent).
89
+ - Conversation memory and in-memory RAG vector store.
90
+ - CLI: forge run, forge models, forge audit.
91
+ - 38 hermetic tests, mypy strict clean, ruff clean.
92
+ - CI matrix across Python 3.11, 3.12, 3.13.
93
+ - PyPI release via OIDC Trusted Publisher (pip install agentforge-oss).
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Sekacorn
3
+ Copyright (c) 2026 sekacorn
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,13 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentforge-oss
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Forge — an open-source, enterprise-ready multi-agent orchestration platform with cost awareness, governance, and security built in.
5
5
  Project-URL: Homepage, https://github.com/sekacorn/AgentForge
6
6
  Project-URL: Documentation, https://github.com/sekacorn/AgentForge#readme
7
7
  Project-URL: Repository, https://github.com/sekacorn/AgentForge
8
8
  Project-URL: Issues, https://github.com/sekacorn/AgentForge/issues
9
- Author-email: Sekacorn <Sekacorn@gmail.com>
10
- Maintainer-email: Sekacorn <Sekacorn@gmail.com>
9
+ Project-URL: Changelog, https://github.com/sekacorn/AgentForge/blob/main/CHANGELOG.md
10
+ Author: sekacorn
11
+ Maintainer: sekacorn
11
12
  License: MIT
12
13
  License-File: LICENSE
13
14
  Keywords: agents,ai,anthropic,claude,enterprise,governance,llm,multi-agent,observability,openai,orchestration,rag
@@ -44,11 +45,19 @@ Requires-Dist: anthropic>=0.20; extra == 'anthropic'
44
45
  Provides-Extra: bedrock
45
46
  Requires-Dist: boto3>=1.34; extra == 'bedrock'
46
47
  Provides-Extra: dev
48
+ Requires-Dist: bandit>=1.7; extra == 'dev'
49
+ Requires-Dist: build>=1.2; extra == 'dev'
47
50
  Requires-Dist: mypy>=1.10; extra == 'dev'
51
+ Requires-Dist: pip-audit>=2.7; extra == 'dev'
48
52
  Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
49
53
  Requires-Dist: pytest-cov>=5.0; extra == 'dev'
50
54
  Requires-Dist: pytest>=8.0; extra == 'dev'
51
55
  Requires-Dist: ruff>=0.6; extra == 'dev'
56
+ Requires-Dist: twine>=5.0; extra == 'dev'
57
+ Provides-Extra: docs
58
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
59
+ Requires-Dist: mkdocs-minify-plugin>=0.8; extra == 'docs'
60
+ Requires-Dist: mkdocs>=1.6; extra == 'docs'
52
61
  Provides-Extra: openai
53
62
  Requires-Dist: openai>=1.0; extra == 'openai'
54
63
  Provides-Extra: otel
@@ -76,7 +85,8 @@ with cost-awareness, security, and compliance built in from line one.**
76
85
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
77
86
  [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/)
78
87
  [![Typed](https://img.shields.io/badge/typed-mypy%20strict-blue.svg)](pyproject.toml)
79
- [![Status: Beta](https://img.shields.io/badge/status-beta-orange.svg)](#whats-shipped-v050)
88
+ [![Docs](https://img.shields.io/badge/docs-github%20pages-blue)](https://sekacorn.github.io/AgentForge/)
89
+ [![Status: Beta](https://img.shields.io/badge/status-beta-orange.svg)](#whats-currently-shipped)
80
90
 
81
91
  </div>
82
92
 
@@ -119,7 +129,7 @@ asyncio.run(main())
119
129
 
120
130
  ---
121
131
 
122
- ## What's shipped (v0.5.0)
132
+ ## What's currently shipped
123
133
 
124
134
  An honest snapshot of what works today versus what is on the way. Everything marked
125
135
  **Shipped** is implemented, typed, and covered by the test suite.
@@ -530,7 +540,7 @@ ruff check . # lint
530
540
  mypy forge # strict type-check
531
541
  ```
532
542
 
533
- The entire 83-test suite runs offline against the deterministic provider — fast,
543
+ The entire 115-test suite runs offline against the deterministic provider — fast,
534
544
  hermetic, and free. CI runs the same checks (ruff, ruff format, mypy strict, pytest)
535
545
  on Python 3.11, 3.12, and 3.13.
536
546
 
@@ -12,7 +12,8 @@ with cost-awareness, security, and compliance built in from line one.**
12
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
13
13
  [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/)
14
14
  [![Typed](https://img.shields.io/badge/typed-mypy%20strict-blue.svg)](pyproject.toml)
15
- [![Status: Beta](https://img.shields.io/badge/status-beta-orange.svg)](#whats-shipped-v050)
15
+ [![Docs](https://img.shields.io/badge/docs-github%20pages-blue)](https://sekacorn.github.io/AgentForge/)
16
+ [![Status: Beta](https://img.shields.io/badge/status-beta-orange.svg)](#whats-currently-shipped)
16
17
 
17
18
  </div>
18
19
 
@@ -55,7 +56,7 @@ asyncio.run(main())
55
56
 
56
57
  ---
57
58
 
58
- ## What's shipped (v0.5.0)
59
+ ## What's currently shipped
59
60
 
60
61
  An honest snapshot of what works today versus what is on the way. Everything marked
61
62
  **Shipped** is implemented, typed, and covered by the test suite.
@@ -466,7 +467,7 @@ ruff check . # lint
466
467
  mypy forge # strict type-check
467
468
  ```
468
469
 
469
- The entire 83-test suite runs offline against the deterministic provider — fast,
470
+ The entire 115-test suite runs offline against the deterministic provider — fast,
470
471
  hermetic, and free. CI runs the same checks (ruff, ruff format, mypy strict, pytest)
471
472
  on Python 3.11, 3.12, and 3.13.
472
473
 
@@ -0,0 +1,70 @@
1
+ # Custom tools
2
+
3
+ Based on `examples/tool_use.py`. Shows how a plain typed Python function becomes
4
+ an agent tool via `@tool`.
5
+
6
+ ## The pattern
7
+
8
+ ```python
9
+ from forge import tool
10
+
11
+ @tool
12
+ def fx_convert(amount: float, rate: float) -> float:
13
+ """Convert an amount of money using an exchange rate.
14
+
15
+ Args:
16
+ amount: The amount in the source currency.
17
+ rate: The exchange rate to apply.
18
+ """
19
+ return round(amount * rate, 2)
20
+ ```
21
+
22
+ The decorator reads your type annotations and Google-style `Args:` docstring to
23
+ build a JSON schema automatically. The agent sees a tool named `fx_convert` with
24
+ two float parameters and a description it can reason about.
25
+
26
+ ## Full example
27
+
28
+ ```python
29
+ import asyncio
30
+ from forge import Orchestrator, ToolRegistry, calculator, tool
31
+
32
+ @tool
33
+ def fx_convert(amount: float, rate: float) -> float:
34
+ """Convert an amount of money using an exchange rate.
35
+
36
+ Args:
37
+ amount: The amount in the source currency.
38
+ rate: The exchange rate to apply.
39
+ """
40
+ return round(amount * rate, 2)
41
+
42
+ async def main() -> None:
43
+ tools = ToolRegistry([calculator, fx_convert])
44
+ async with Orchestrator() as forge:
45
+ result = await forge.run(
46
+ "Compute 250 * 0.92 to convert USD to EUR, then state the result",
47
+ mode="single",
48
+ tools=tools,
49
+ )
50
+ print(result.output)
51
+ print()
52
+ print(result.usage.format_table())
53
+
54
+ asyncio.run(main())
55
+ ```
56
+
57
+ ## Run it
58
+
59
+ ```bash
60
+ python examples/tool_use.py
61
+ ```
62
+
63
+ No API key needed -- the Echo provider exercises the tool path end to end.
64
+
65
+ ## Key points
66
+
67
+ - **Type all parameters.** The JSON schema is generated from annotations.
68
+ - **Write a docstring.** The first line becomes the tool description; `Args:` generates parameter descriptions.
69
+ - **Mark side effects.** Tools that touch the network or filesystem should use `@tool(dangerous=True)` so the sandbox gates them.
70
+ - **Use ToolRegistry.** Group tools into a registry and pass it to `Orchestrator.run()`.
@@ -0,0 +1,18 @@
1
+ # Examples
2
+
3
+ Runnable end-to-end scripts in the [`examples/`](https://github.com/sekacorn/AgentForge/tree/main/examples) directory. Every example works offline with the Echo provider unless noted otherwise.
4
+
5
+ | Example | What it demonstrates |
6
+ |---|---|
7
+ | [Custom tools](custom-tools.md) | The `@tool` decorator, custom functions, and tool registries |
8
+ | [Parallel supervisor](parallel-supervisor.md) | Supervisor mode with concurrent workers and cost reporting |
9
+ | [Persistent RAG](persistent-rag.md) | SQLite-backed memory that survives process restarts |
10
+ | [Policy governance](policy-governance.md) | Deny, approve, and log rules with human-in-the-loop gates |
11
+ | [OpenTelemetry](otel-tracing.md) | Console span export and OTLP endpoint configuration |
12
+
13
+ Additional scripts in the repository:
14
+
15
+ - **`examples/quickstart.py`** -- a multi-agent run with live event rendering
16
+ - **`examples/rag.py`** -- in-memory RAG with retrieval-augmented generation
17
+ - **`examples/enterprise_governance.py`** -- RBAC, budgets, audit verification, PII redaction
18
+ - **`examples/rag_pgvector.py`** -- pgvector-backed durable RAG with PostgreSQL
@@ -0,0 +1,98 @@
1
+ # OpenTelemetry tracing
2
+
3
+ Based on `examples/otel_tracing.py`. Shows console span export and how to wire
4
+ up a real OTel collector.
5
+
6
+ ## Console export (zero infra)
7
+
8
+ ```python
9
+ import asyncio
10
+ from forge import ForgeConfig, Orchestrator
11
+
12
+ async def main() -> None:
13
+ config = ForgeConfig(
14
+ otel_enabled=True,
15
+ otel_service_name="forge-demo",
16
+ )
17
+ async with Orchestrator(config) as forge:
18
+ result = await forge.run(
19
+ "Calculate 15% of 4200 and summarize the result",
20
+ mode="single",
21
+ )
22
+ print(result.output)
23
+ print(result.usage.format_table())
24
+ print("\nSpans exported above (ConsoleSpanExporter).")
25
+
26
+ asyncio.run(main())
27
+ ```
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install "agentforge-oss[otel]"
33
+ ```
34
+
35
+ ## Run it
36
+
37
+ ```bash
38
+ python examples/otel_tracing.py
39
+ ```
40
+
41
+ Spans are printed to the console by default. You'll see a tree of spans:
42
+
43
+ ```
44
+ forge.run
45
+ forge.agent
46
+ forge.model_call
47
+ forge.tool_call
48
+ ```
49
+
50
+ ## OTLP export (production)
51
+
52
+ Point at a real collector to send traces to Jaeger, Grafana Tempo, Datadog, or
53
+ any OTLP-compatible backend:
54
+
55
+ ```bash
56
+ export FORGE_OTEL_ENABLED=true
57
+ export FORGE_OTEL_ENDPOINT="http://localhost:4317"
58
+ export FORGE_OTEL_SERVICE_NAME="forge-production"
59
+ python examples/otel_tracing.py
60
+ ```
61
+
62
+ Or configure programmatically:
63
+
64
+ ```python
65
+ import os
66
+
67
+ config = ForgeConfig(
68
+ otel_enabled=True,
69
+ otel_service_name="forge-production",
70
+ otel_endpoint=os.environ.get("FORGE_OTEL_ENDPOINT"),
71
+ )
72
+ ```
73
+
74
+ ## Jaeger quick setup
75
+
76
+ To see traces visually with Jaeger:
77
+
78
+ ```bash
79
+ docker run -d --name jaeger \
80
+ -p 16686:16686 \
81
+ -p 4317:4317 \
82
+ jaegertracing/all-in-one:latest
83
+
84
+ export FORGE_OTEL_ENABLED=true
85
+ export FORGE_OTEL_ENDPOINT="http://localhost:4317"
86
+ python examples/otel_tracing.py
87
+ ```
88
+
89
+ Open `http://localhost:16686` to browse traces.
90
+
91
+ ## Metrics
92
+
93
+ In addition to traces, Forge exports these metrics when OTel is enabled:
94
+
95
+ - Run count
96
+ - Run duration
97
+ - Token usage (input/output)
98
+ - Tool call count
@@ -0,0 +1,66 @@
1
+ # Parallel supervisor
2
+
3
+ Shows a supervisor run with concurrent workers, budget caps, and the usage report.
4
+
5
+ ## How it works
6
+
7
+ In `supervisor` mode, a supervisor agent decomposes the goal into independent
8
+ subtasks and spawns a focused worker agent for each. Workers run concurrently
9
+ via `asyncio.gather` in bounded batches controlled by `max_workers`.
10
+
11
+ A pre-flight budget check estimates worst-case spend before spawning workers.
12
+ If a worker fails, it emits `WORKER_FAILED` and returns a partial result -- its
13
+ peers are never cancelled.
14
+
15
+ ## Full example
16
+
17
+ ```python
18
+ import asyncio
19
+ from forge import Orchestrator, ForgeConfig, BudgetConfig
20
+
21
+ async def main() -> None:
22
+ config = ForgeConfig(
23
+ budget=BudgetConfig(max_workers=3, max_usd_per_run=0.25)
24
+ )
25
+ async with Orchestrator(config) as forge:
26
+ result = await forge.run(
27
+ "Summarize our product, draft a pricing page, and write an FAQ",
28
+ mode="supervisor",
29
+ )
30
+ print(result.output)
31
+ print(result.usage.format_table())
32
+
33
+ asyncio.run(main())
34
+ ```
35
+
36
+ ## What you'll see
37
+
38
+ The usage table breaks down tokens and cost per model and per agent:
39
+
40
+ ```
41
+ Model Input Output Cost
42
+ echo-pro 150 75 $0.0000
43
+ ─────────────────────────────────────────
44
+ Total 150 75 $0.0000
45
+ ```
46
+
47
+ With a real provider (Anthropic, OpenAI), the cost column shows actual spend
48
+ against the `max_usd_per_run` cap.
49
+
50
+ ## Configuration
51
+
52
+ | Field | Default | Description |
53
+ |---|---|---|
54
+ | `max_workers` | `5` | Maximum concurrent workers per supervisor batch |
55
+ | `max_usd_per_run` | None | Hard USD cap; the run halts if exceeded |
56
+ | `max_tokens_per_run` | None | Hard token cap |
57
+ | `max_steps_per_agent` | `12` | Maximum reasoning/acting iterations per agent |
58
+
59
+ ## Run it
60
+
61
+ ```bash
62
+ python examples/quickstart.py
63
+ ```
64
+
65
+ The quickstart example uses supervisor mode with live event rendering so you can
66
+ watch the supervisor plan, delegate, and synthesize in real time.
@@ -0,0 +1,69 @@
1
+ # Persistent RAG
2
+
3
+ Based on `examples/rag_persistent.py`. Shows SQLite-backed memory that survives
4
+ process restarts.
5
+
6
+ ## The idea
7
+
8
+ The default `InMemoryVectorStore` loses all facts when the process exits. The
9
+ `SQLiteMemoryStore` writes facts to a local database file so they persist across
10
+ restarts -- no external infrastructure needed.
11
+
12
+ ## Full example
13
+
14
+ ```python
15
+ import asyncio
16
+ from forge.memory.sqlite import SQLiteMemoryStore
17
+
18
+ async def main() -> None:
19
+ async with SQLiteMemoryStore("demo_memory.db") as store:
20
+ count_before = len(await store.search("forge", k=100))
21
+ if count_before == 0:
22
+ print("First run -- storing facts...")
23
+ await store.add("Forge routes cheap tasks to small models to save cost.")
24
+ await store.add("The audit log is hash-chained and tamper-evident.")
25
+ await store.add("Ollama runs local LLMs with zero API cost.")
26
+ print("Stored 3 facts. Run again to retrieve them.")
27
+ else:
28
+ print(f"Second run -- found {count_before} stored facts.")
29
+ hits = await store.search("how does Forge reduce cost?", k=2)
30
+ for hit in hits:
31
+ print(f" [{hit.score:.3f}] {hit.text}")
32
+
33
+ asyncio.run(main())
34
+ ```
35
+
36
+ ## Run it
37
+
38
+ ```bash
39
+ pip install "agentforge-oss[sqlite]"
40
+ python examples/rag_persistent.py
41
+ python examples/rag_persistent.py # run again -- facts are still there
42
+ ```
43
+
44
+ ## First run output
45
+
46
+ ```
47
+ First run -- storing facts...
48
+ Stored 3 facts. Run again to retrieve them.
49
+ ```
50
+
51
+ ## Second run output
52
+
53
+ ```
54
+ Second run -- found 3 stored facts.
55
+ [0.567] Forge routes cheap tasks to small models to save cost.
56
+ [0.432] Ollama runs local LLMs with zero API cost.
57
+ ```
58
+
59
+ ## pgvector alternative
60
+
61
+ For production-scale RAG with real ANN (approximate nearest neighbor) search,
62
+ use the `PGVectorMemoryStore` backed by PostgreSQL + pgvector:
63
+
64
+ ```bash
65
+ pip install "agentforge-oss[pgvector]"
66
+ python examples/rag_pgvector.py
67
+ ```
68
+
69
+ See the [Memory & RAG guide](../guides/memory.md) for details on all three backends.
@@ -0,0 +1,128 @@
1
+ # Policy governance
2
+
3
+ Based on `examples/policy_governance.py`. Demonstrates the three policy-as-code
4
+ governance patterns: deny, approve, and log.
5
+
6
+ ## Pattern 1: Hard deny
7
+
8
+ Block a specific tool unconditionally:
9
+
10
+ ```python
11
+ from forge import PolicyRule, PolicySet
12
+
13
+ policy = PolicySet()
14
+ policy.add(PolicyRule(
15
+ name="block-calculator",
16
+ description="Calculator is blocked by policy",
17
+ tool_names=["calculator"],
18
+ condition=lambda name, args: True,
19
+ action="deny",
20
+ ))
21
+ ```
22
+
23
+ When the agent tries to call `calculator`, the sandbox rejects the call
24
+ immediately and returns an error result.
25
+
26
+ ## Pattern 2: Human approval gate
27
+
28
+ Require a human (or automated system) to approve before a tool runs:
29
+
30
+ ```python
31
+ from typing import Any
32
+
33
+ async def my_approver(tool_name: str, args: dict[str, Any]) -> bool:
34
+ print(f"[APPROVAL GATE] Tool '{tool_name}' requested with args: {args}")
35
+ print("[APPROVAL GATE] Auto-approving for demo purposes.")
36
+ return True
37
+
38
+ policy = PolicySet()
39
+ policy.add(PolicyRule(
40
+ name="require-approval-for-calculator",
41
+ description="Calculator requires human approval",
42
+ tool_names=["calculator"],
43
+ condition=lambda name, args: True,
44
+ action="approve",
45
+ approver=my_approver,
46
+ ))
47
+ ```
48
+
49
+ The `approver` is an async function that receives the tool name and arguments.
50
+ Return `True` to allow, `False` to deny. In production, this could call a Slack
51
+ bot, a webhook, or a manual review queue.
52
+
53
+ ## Pattern 3: Audit log
54
+
55
+ Log every tool call without blocking:
56
+
57
+ ```python
58
+ policy = PolicySet()
59
+ policy.add(PolicyRule(
60
+ name="log-all-tools",
61
+ description="Log every tool call for audit",
62
+ tool_names=["*"],
63
+ condition=lambda name, args: True,
64
+ action="log",
65
+ ))
66
+ ```
67
+
68
+ The wildcard `"*"` matches any tool name. Log rules continue to the next rule
69
+ (they don't short-circuit like deny/approve).
70
+
71
+ ## Full example
72
+
73
+ ```python
74
+ import asyncio
75
+ from forge import EchoProvider, ForgeConfig, Orchestrator, PolicyRule, PolicySet, tool
76
+
77
+ @tool
78
+ def calculator(expression: str) -> str:
79
+ """Evaluate a math expression.
80
+
81
+ Args:
82
+ expression: The expression to evaluate.
83
+ """
84
+ return str(eval(expression))
85
+
86
+ async def main() -> None:
87
+ policy = PolicySet()
88
+ policy.add(PolicyRule(
89
+ name="block-calculator",
90
+ description="Calculator is blocked by policy",
91
+ tool_names=["calculator"],
92
+ condition=lambda name, args: True,
93
+ action="deny",
94
+ ))
95
+
96
+ forge_instance = Orchestrator(ForgeConfig(), providers={"echo": EchoProvider()})
97
+ async with forge_instance as forge:
98
+ result = await forge.run(
99
+ "Calculate 2 + 2",
100
+ mode="single",
101
+ tools=[calculator],
102
+ policy_set=policy,
103
+ )
104
+ print(f"Output: {result.output}")
105
+
106
+ asyncio.run(main())
107
+ ```
108
+
109
+ ## Run it
110
+
111
+ ```bash
112
+ python examples/policy_governance.py
113
+ ```
114
+
115
+ ## Events
116
+
117
+ Subscribe to the event bus to observe policy decisions in real time:
118
+
119
+ ```python
120
+ def on_event(event):
121
+ if "policy" in event.type.value:
122
+ print(f" [{event.type.value}] {event.data}")
123
+
124
+ forge.subscribe(on_event)
125
+ ```
126
+
127
+ Four policy event types: `POLICY_EVALUATED`, `POLICY_APPROVED`, `POLICY_DENIED`,
128
+ `POLICY_LOGGED`.