baiam-agents-builder 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.
- baiam_agents_builder-0.1.0/.gitignore +29 -0
- baiam_agents_builder-0.1.0/.gitlab-ci.yml +85 -0
- baiam_agents_builder-0.1.0/.pre-commit-config.yaml +34 -0
- baiam_agents_builder-0.1.0/.python-version +1 -0
- baiam_agents_builder-0.1.0/AGENTS.md +11 -0
- baiam_agents_builder-0.1.0/Makefile +56 -0
- baiam_agents_builder-0.1.0/PKG-INFO +106 -0
- baiam_agents_builder-0.1.0/README.md +88 -0
- baiam_agents_builder-0.1.0/codecov.yml +19 -0
- baiam_agents_builder-0.1.0/commitlint.config.cjs +11 -0
- baiam_agents_builder-0.1.0/pyproject.toml +65 -0
- baiam_agents_builder-0.1.0/scripts/publish.sh +27 -0
- baiam_agents_builder-0.1.0/src/agents_builder/__init__.py +82 -0
- baiam_agents_builder-0.1.0/src/agents_builder/constants.py +1 -0
- baiam_agents_builder-0.1.0/src/agents_builder/eval/__init__.py +72 -0
- baiam_agents_builder-0.1.0/src/agents_builder/eval/annotator.py +48 -0
- baiam_agents_builder-0.1.0/src/agents_builder/eval/exceptions.py +10 -0
- baiam_agents_builder-0.1.0/src/agents_builder/eval/settings.py +20 -0
- baiam_agents_builder-0.1.0/src/agents_builder/eval/utils.py +8 -0
- baiam_agents_builder-0.1.0/src/agents_builder/exceptions.py +19 -0
- baiam_agents_builder-0.1.0/src/agents_builder/langgraph/__init__.py +46 -0
- baiam_agents_builder-0.1.0/src/agents_builder/llm/__init__.py +19 -0
- baiam_agents_builder-0.1.0/src/agents_builder/llm/exceptions.py +18 -0
- baiam_agents_builder-0.1.0/src/agents_builder/llm/factory.py +44 -0
- baiam_agents_builder-0.1.0/src/agents_builder/llm/llm.py +46 -0
- baiam_agents_builder-0.1.0/src/agents_builder/llm/settings.py +33 -0
- baiam_agents_builder-0.1.0/src/agents_builder/mixins.py +60 -0
- baiam_agents_builder-0.1.0/src/agents_builder/py.typed +0 -0
- baiam_agents_builder-0.1.0/src/agents_builder/settings.py +14 -0
- baiam_agents_builder-0.1.0/src/agents_builder/utils.py +45 -0
- baiam_agents_builder-0.1.0/tests/__init__.py +0 -0
- baiam_agents_builder-0.1.0/tests/e2e/test_agent_graph.py +20 -0
- baiam_agents_builder-0.1.0/tests/fixtures/__init__.py +0 -0
- baiam_agents_builder-0.1.0/tests/fixtures/graph.py +57 -0
- baiam_agents_builder-0.1.0/tests/fixtures/runtime_components.py +90 -0
- baiam_agents_builder-0.1.0/tests/integration/test_providers.py +33 -0
- baiam_agents_builder-0.1.0/tests/unit/__init__.py +0 -0
- baiam_agents_builder-0.1.0/tests/unit/test_agents_builder/test_agent.py +73 -0
- baiam_agents_builder-0.1.0/tests/unit/test_configuration.py +58 -0
- baiam_agents_builder-0.1.0/tests/unit/test_graph_primitives.py +33 -0
- baiam_agents_builder-0.1.0/tests/unit/test_llm/test_llm.py +99 -0
- baiam_agents_builder-0.1.0/tests/unit/test_mcp.py +46 -0
- baiam_agents_builder-0.1.0/tests/unit/test_publish_script.py +74 -0
- baiam_agents_builder-0.1.0/tests/unit/test_tracing.py +80 -0
- baiam_agents_builder-0.1.0/uv.lock +1703 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.python-version.local
|
|
6
|
+
|
|
7
|
+
# Virtual environments and tools
|
|
8
|
+
.venv/
|
|
9
|
+
.cache/
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
.ty_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
coverage.xml
|
|
15
|
+
htmlcov/
|
|
16
|
+
|
|
17
|
+
# Builds
|
|
18
|
+
build/
|
|
19
|
+
dist/
|
|
20
|
+
|
|
21
|
+
# Editors and OS
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
.DS_Store
|
|
25
|
+
|
|
26
|
+
# Environment and secrets
|
|
27
|
+
.env
|
|
28
|
+
.env.*
|
|
29
|
+
!.env.example
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
image: python:3.12
|
|
2
|
+
|
|
3
|
+
workflow:
|
|
4
|
+
rules:
|
|
5
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
|
|
6
|
+
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "dev" && $CI_COMMIT_REF_PROTECTED == "true"'
|
|
7
|
+
- when: never
|
|
8
|
+
|
|
9
|
+
stages:
|
|
10
|
+
- checks
|
|
11
|
+
- test
|
|
12
|
+
|
|
13
|
+
variables:
|
|
14
|
+
UV_SYSTEM_PYTHON: "1"
|
|
15
|
+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
cache:
|
|
19
|
+
key:
|
|
20
|
+
files:
|
|
21
|
+
- uv.lock
|
|
22
|
+
paths:
|
|
23
|
+
- .venv/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
before_script:
|
|
27
|
+
- pip install uv
|
|
28
|
+
- uv sync --group dev --all-extras
|
|
29
|
+
|
|
30
|
+
ruff:
|
|
31
|
+
stage: checks
|
|
32
|
+
script:
|
|
33
|
+
- make lint
|
|
34
|
+
|
|
35
|
+
ty:
|
|
36
|
+
stage: checks
|
|
37
|
+
script:
|
|
38
|
+
- make type-check
|
|
39
|
+
|
|
40
|
+
bandit:
|
|
41
|
+
stage: checks
|
|
42
|
+
script:
|
|
43
|
+
- make security
|
|
44
|
+
|
|
45
|
+
pytest:
|
|
46
|
+
stage: test
|
|
47
|
+
script:
|
|
48
|
+
- make test-cov
|
|
49
|
+
artifacts:
|
|
50
|
+
paths:
|
|
51
|
+
- coverage.xml
|
|
52
|
+
|
|
53
|
+
check-package:
|
|
54
|
+
stage: test
|
|
55
|
+
needs: ["pytest"]
|
|
56
|
+
script:
|
|
57
|
+
- make build
|
|
58
|
+
- pip install dist/*.whl
|
|
59
|
+
|
|
60
|
+
codecov:
|
|
61
|
+
stage: test
|
|
62
|
+
needs: ["pytest"]
|
|
63
|
+
script:
|
|
64
|
+
- curl -Os https://cli.codecov.io/latest/linux/codecov
|
|
65
|
+
- chmod +x codecov
|
|
66
|
+
- ./codecov upload-process -t $CODECOV_TOKEN
|
|
67
|
+
|
|
68
|
+
conventional-commits:
|
|
69
|
+
stage: checks
|
|
70
|
+
image: node:20
|
|
71
|
+
rules:
|
|
72
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
73
|
+
before_script: []
|
|
74
|
+
script:
|
|
75
|
+
- npm install -g @commitlint/cli @commitlint/config-conventional
|
|
76
|
+
- echo "$CI_MERGE_REQUEST_TITLE" > pr_title.txt
|
|
77
|
+
- |
|
|
78
|
+
npx commitlint --config commitlint.config.cjs --edit pr_title.txt || {
|
|
79
|
+
echo "❌ PR title must follow Conventional Commits format (e.g. feat:, fix:)"
|
|
80
|
+
exit 1
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
default:
|
|
84
|
+
retry: 1
|
|
85
|
+
timeout: 10m
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.13.3
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/compilerla/conventional-pre-commit
|
|
10
|
+
rev: v3.6.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: conventional-pre-commit
|
|
13
|
+
stages: [commit-msg]
|
|
14
|
+
|
|
15
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
16
|
+
rev: v5.0.0
|
|
17
|
+
hooks:
|
|
18
|
+
- id: trailing-whitespace
|
|
19
|
+
- id: end-of-file-fixer
|
|
20
|
+
- id: check-yaml
|
|
21
|
+
- id: check-added-large-files
|
|
22
|
+
args: [--maxkb=1000]
|
|
23
|
+
- id: check-json
|
|
24
|
+
- id: check-toml
|
|
25
|
+
- id: detect-private-key
|
|
26
|
+
- id: mixed-line-ending
|
|
27
|
+
- id: check-merge-conflict
|
|
28
|
+
|
|
29
|
+
- repo: https://github.com/PyCQA/bandit
|
|
30
|
+
rev: 1.9.4
|
|
31
|
+
hooks:
|
|
32
|
+
- id: bandit
|
|
33
|
+
args: [-c, pyproject.toml, -r, src]
|
|
34
|
+
additional_dependencies: ["bandit[toml]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Agent Instructions
|
|
2
|
+
|
|
3
|
+
## Project conventions
|
|
4
|
+
|
|
5
|
+
- This is a Python project managed with uv and a src layout.
|
|
6
|
+
- Read relevant code before changing it and preserve unrelated user changes.
|
|
7
|
+
- Use `uv add` or `uv add --dev` for dependencies; do not hand-edit the lockfile.
|
|
8
|
+
- Keep application code under `src/` and tests under `tests/`.
|
|
9
|
+
- Add or update tests for behavior changes.
|
|
10
|
+
- Run `make ci` after code changes when feasible. Report any checks that could not run.
|
|
11
|
+
- Do not commit unless a human has validated the work and explicitly requested a commit.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.PHONY: help install dev-install setup-hooks format lint type-check security test test-cov build ci ci-fast clean
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available targets:"
|
|
5
|
+
@echo " make install Install runtime dependencies"
|
|
6
|
+
@echo " make dev-install Install development dependencies and Git hooks"
|
|
7
|
+
@echo " make format Format the codebase"
|
|
8
|
+
@echo " make lint Check linting and formatting"
|
|
9
|
+
@echo " make type-check Run static type checks"
|
|
10
|
+
@echo " make security Run security checks"
|
|
11
|
+
@echo " make test Run tests"
|
|
12
|
+
@echo " make test-cov Run tests with coverage"
|
|
13
|
+
@echo " make build Build source and wheel distributions"
|
|
14
|
+
@echo " make ci Run the full local CI suite"
|
|
15
|
+
|
|
16
|
+
install:
|
|
17
|
+
uv sync --no-dev --all-extras
|
|
18
|
+
|
|
19
|
+
dev-install:
|
|
20
|
+
uv sync --group dev --all-extras
|
|
21
|
+
$(MAKE) setup-hooks
|
|
22
|
+
|
|
23
|
+
setup-hooks:
|
|
24
|
+
uv run pre-commit install
|
|
25
|
+
uv run pre-commit install --hook-type commit-msg
|
|
26
|
+
|
|
27
|
+
format:
|
|
28
|
+
uv run ruff format .
|
|
29
|
+
uv run ruff check --fix .
|
|
30
|
+
|
|
31
|
+
lint:
|
|
32
|
+
uv run ruff check .
|
|
33
|
+
uv run ruff format --check .
|
|
34
|
+
|
|
35
|
+
type-check:
|
|
36
|
+
uv run ty check .
|
|
37
|
+
|
|
38
|
+
security:
|
|
39
|
+
uv run bandit -c pyproject.toml -r src
|
|
40
|
+
|
|
41
|
+
test:
|
|
42
|
+
uv run pytest
|
|
43
|
+
|
|
44
|
+
test-cov:
|
|
45
|
+
uv run pytest --cov=agents_builder --cov-branch --cov-report=term-missing:skip-covered --cov-report=xml --cov-fail-under=95
|
|
46
|
+
|
|
47
|
+
build:
|
|
48
|
+
uv run python -m build
|
|
49
|
+
|
|
50
|
+
ci: lint type-check security test-cov build
|
|
51
|
+
|
|
52
|
+
ci-fast: lint type-check test
|
|
53
|
+
|
|
54
|
+
clean:
|
|
55
|
+
rm -rf .coverage coverage.xml htmlcov .pytest_cache .ruff_cache .ty_cache build dist
|
|
56
|
+
find . -type d -name __pycache__ -prune -exec rm -rf {} +
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: baiam-agents-builder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed agent primitives and tracing for Baiam Agent
|
|
5
|
+
Requires-Python: <3.13,>=3.12
|
|
6
|
+
Requires-Dist: arize-phoenix-client<3.0.0,>=2.6.0
|
|
7
|
+
Requires-Dist: arize-phoenix-otel==0.13.1
|
|
8
|
+
Requires-Dist: langchain-core<2.0.0,>=1.8.4
|
|
9
|
+
Requires-Dist: langchain-mcp-adapters<0.4.0,>=0.3.2
|
|
10
|
+
Requires-Dist: langchain-ollama<2.0.0,>=1.1.0
|
|
11
|
+
Requires-Dist: langchain-openrouter<0.4.0,>=0.3.0
|
|
12
|
+
Requires-Dist: langgraph<1.3.0,>=1.2.24
|
|
13
|
+
Requires-Dist: opentelemetry-api<2.0.0,>=1.37.0
|
|
14
|
+
Requires-Dist: pydantic-settings<3.0.0,>=2.12.0
|
|
15
|
+
Requires-Dist: pydantic<3.0.0,>=2.12.5
|
|
16
|
+
Requires-Dist: pyyaml<7.0.0,>=6.0.2
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# baiam-agents-builder
|
|
20
|
+
|
|
21
|
+
Typed agent primitives and tracing for Baiam Agent. Distribution name:
|
|
22
|
+
`baiam-agents-builder`; Python import namespace: `agents_builder`.
|
|
23
|
+
|
|
24
|
+
This is a separate project starting at version `0.1.0`, with a fresh Git history.
|
|
25
|
+
It retains the code needed by the current Baiam Agent checkout, plus the MCP and
|
|
26
|
+
Ollama features retained explicitly for future use.
|
|
27
|
+
|
|
28
|
+
## Included API
|
|
29
|
+
|
|
30
|
+
- `Agent`: configuration, cached LLM factory, lazy graph construction,
|
|
31
|
+
`load_tool()` with MCP caching, and `push()` to save a graph image.
|
|
32
|
+
- `Prompt`, `Node`, `RouterNode`, and `LLMNode`: primitives for Baiam's own nodes.
|
|
33
|
+
- `LLM`, `LLMFactory`, `OpenRouterLLM`, and `OllamaLLM`, with validated settings.
|
|
34
|
+
- `FromConfigMixin`: `from_config()`, `from_kwargs()`, and `get_config_class()`.
|
|
35
|
+
- `TraceAnnotator` and `PhoenixTraceAnnotator`, including Git revision labels.
|
|
36
|
+
|
|
37
|
+
The old retrieval nodes/states, deletion strategies, message/context helpers,
|
|
38
|
+
agent/node evaluation frameworks, and unused type aliases are excluded.
|
|
39
|
+
Baiam keeps its own evaluation runners, assertions, and trajectories.
|
|
40
|
+
|
|
41
|
+
The package uses `langchain-core` directly. OpenEvals belongs to Baiam's own
|
|
42
|
+
evaluation code and is not a runtime dependency here.
|
|
43
|
+
|
|
44
|
+
## Use from Baiam Agent
|
|
45
|
+
|
|
46
|
+
In the sibling `baiam-agent` checkout:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
uv remove agents-builder
|
|
50
|
+
uv add --editable ../baiam-agents-builder
|
|
51
|
+
uv add 'openevals>=0.2.0,<1.0.0'
|
|
52
|
+
make ci
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Existing `agents_builder` imports and YAML module paths remain valid. Replace the
|
|
56
|
+
old distribution rather than installing both: they provide the same Python
|
|
57
|
+
namespace. For deployment, publish this distribution and replace the local path
|
|
58
|
+
with a version constraint on `baiam-agents-builder`.
|
|
59
|
+
|
|
60
|
+
Configuration precedence remains explicit constructor values, YAML at
|
|
61
|
+
`/config/config.yaml`, environment variables, dotenv, then secrets. Baiam also
|
|
62
|
+
provides its own YAML loading through `load_component()` and agent settings.
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
Requires Python 3.12 and [uv](https://docs.astral.sh/uv/).
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
uv lock
|
|
70
|
+
make dev-install
|
|
71
|
+
make ci
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use `make help` to list the available development commands.
|
|
75
|
+
|
|
76
|
+
`make ci` checks lint and formatting, types, security, tests with at least 95%
|
|
77
|
+
branch-aware coverage, and both source and wheel builds. Tests cover graph
|
|
78
|
+
execution, MCP caching, configuration, provider construction, and tracing. They
|
|
79
|
+
do not contact live Ollama, OpenRouter, MCP, or Phoenix services.
|
|
80
|
+
|
|
81
|
+
## CI and publishing
|
|
82
|
+
|
|
83
|
+
The GitLab pipeline uses the same Makefile targets as local development. It runs
|
|
84
|
+
for merge requests, the default branch, and protected tags. Set the GitLab
|
|
85
|
+
default branch to `dev` when connecting this repository. Codecov upload runs only
|
|
86
|
+
when `CODECOV_TOKEN` is configured.
|
|
87
|
+
|
|
88
|
+
Publishing is manual; CI builds artifacts without publishing a release. After
|
|
89
|
+
confirming that the distribution name is available on PyPI and the token account
|
|
90
|
+
can publish it, run:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
read -rsp 'PyPI token: ' UV_PUBLISH_TOKEN
|
|
94
|
+
echo
|
|
95
|
+
export UV_PUBLISH_TOKEN
|
|
96
|
+
./scripts/publish.sh 0.1.1
|
|
97
|
+
unset UV_PUBLISH_TOKEN
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The script updates the version in `pyproject.toml` and `uv.lock`, builds into
|
|
101
|
+
`dist/<version>/`, and publishes only that version's wheel and source distribution.
|
|
102
|
+
Run `make ci` before publishing, then commit the version files after a successful
|
|
103
|
+
release.
|
|
104
|
+
|
|
105
|
+
This reduced package is derived from the local `agents-builder` codebase. The
|
|
106
|
+
original project and the Baiam Agent checkout are not modified by its creation.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# baiam-agents-builder
|
|
2
|
+
|
|
3
|
+
Typed agent primitives and tracing for Baiam Agent. Distribution name:
|
|
4
|
+
`baiam-agents-builder`; Python import namespace: `agents_builder`.
|
|
5
|
+
|
|
6
|
+
This is a separate project starting at version `0.1.0`, with a fresh Git history.
|
|
7
|
+
It retains the code needed by the current Baiam Agent checkout, plus the MCP and
|
|
8
|
+
Ollama features retained explicitly for future use.
|
|
9
|
+
|
|
10
|
+
## Included API
|
|
11
|
+
|
|
12
|
+
- `Agent`: configuration, cached LLM factory, lazy graph construction,
|
|
13
|
+
`load_tool()` with MCP caching, and `push()` to save a graph image.
|
|
14
|
+
- `Prompt`, `Node`, `RouterNode`, and `LLMNode`: primitives for Baiam's own nodes.
|
|
15
|
+
- `LLM`, `LLMFactory`, `OpenRouterLLM`, and `OllamaLLM`, with validated settings.
|
|
16
|
+
- `FromConfigMixin`: `from_config()`, `from_kwargs()`, and `get_config_class()`.
|
|
17
|
+
- `TraceAnnotator` and `PhoenixTraceAnnotator`, including Git revision labels.
|
|
18
|
+
|
|
19
|
+
The old retrieval nodes/states, deletion strategies, message/context helpers,
|
|
20
|
+
agent/node evaluation frameworks, and unused type aliases are excluded.
|
|
21
|
+
Baiam keeps its own evaluation runners, assertions, and trajectories.
|
|
22
|
+
|
|
23
|
+
The package uses `langchain-core` directly. OpenEvals belongs to Baiam's own
|
|
24
|
+
evaluation code and is not a runtime dependency here.
|
|
25
|
+
|
|
26
|
+
## Use from Baiam Agent
|
|
27
|
+
|
|
28
|
+
In the sibling `baiam-agent` checkout:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
uv remove agents-builder
|
|
32
|
+
uv add --editable ../baiam-agents-builder
|
|
33
|
+
uv add 'openevals>=0.2.0,<1.0.0'
|
|
34
|
+
make ci
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Existing `agents_builder` imports and YAML module paths remain valid. Replace the
|
|
38
|
+
old distribution rather than installing both: they provide the same Python
|
|
39
|
+
namespace. For deployment, publish this distribution and replace the local path
|
|
40
|
+
with a version constraint on `baiam-agents-builder`.
|
|
41
|
+
|
|
42
|
+
Configuration precedence remains explicit constructor values, YAML at
|
|
43
|
+
`/config/config.yaml`, environment variables, dotenv, then secrets. Baiam also
|
|
44
|
+
provides its own YAML loading through `load_component()` and agent settings.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
Requires Python 3.12 and [uv](https://docs.astral.sh/uv/).
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
uv lock
|
|
52
|
+
make dev-install
|
|
53
|
+
make ci
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Use `make help` to list the available development commands.
|
|
57
|
+
|
|
58
|
+
`make ci` checks lint and formatting, types, security, tests with at least 95%
|
|
59
|
+
branch-aware coverage, and both source and wheel builds. Tests cover graph
|
|
60
|
+
execution, MCP caching, configuration, provider construction, and tracing. They
|
|
61
|
+
do not contact live Ollama, OpenRouter, MCP, or Phoenix services.
|
|
62
|
+
|
|
63
|
+
## CI and publishing
|
|
64
|
+
|
|
65
|
+
The GitLab pipeline uses the same Makefile targets as local development. It runs
|
|
66
|
+
for merge requests, the default branch, and protected tags. Set the GitLab
|
|
67
|
+
default branch to `dev` when connecting this repository. Codecov upload runs only
|
|
68
|
+
when `CODECOV_TOKEN` is configured.
|
|
69
|
+
|
|
70
|
+
Publishing is manual; CI builds artifacts without publishing a release. After
|
|
71
|
+
confirming that the distribution name is available on PyPI and the token account
|
|
72
|
+
can publish it, run:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
read -rsp 'PyPI token: ' UV_PUBLISH_TOKEN
|
|
76
|
+
echo
|
|
77
|
+
export UV_PUBLISH_TOKEN
|
|
78
|
+
./scripts/publish.sh 0.1.1
|
|
79
|
+
unset UV_PUBLISH_TOKEN
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The script updates the version in `pyproject.toml` and `uv.lock`, builds into
|
|
83
|
+
`dist/<version>/`, and publishes only that version's wheel and source distribution.
|
|
84
|
+
Run `make ci` before publishing, then commit the version files after a successful
|
|
85
|
+
release.
|
|
86
|
+
|
|
87
|
+
This reduced package is derived from the local `agents-builder` codebase. The
|
|
88
|
+
original project and the Baiam Agent checkout are not modified by its creation.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
coverage:
|
|
2
|
+
range: 50..95
|
|
3
|
+
round: down
|
|
4
|
+
precision: 2
|
|
5
|
+
status:
|
|
6
|
+
project:
|
|
7
|
+
default:
|
|
8
|
+
target: auto
|
|
9
|
+
threshold: 2%
|
|
10
|
+
patch:
|
|
11
|
+
default:
|
|
12
|
+
target: 95%
|
|
13
|
+
|
|
14
|
+
comment:
|
|
15
|
+
layout: "condensed_header, condensed_files, condensed_footer"
|
|
16
|
+
require_changes: false
|
|
17
|
+
require_base: false
|
|
18
|
+
require_head: true
|
|
19
|
+
hide_project_coverage: true
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "baiam-agents-builder"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Typed agent primitives and tracing for Baiam Agent"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12,<3.13"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"arize-phoenix-client>=2.6.0,<3.0.0",
|
|
13
|
+
"arize-phoenix-otel==0.13.1",
|
|
14
|
+
"langchain-core>=1.8.4,<2.0.0",
|
|
15
|
+
"langchain-mcp-adapters>=0.3.2,<0.4.0",
|
|
16
|
+
"langchain-ollama>=1.1.0,<2.0.0",
|
|
17
|
+
"langchain-openrouter>=0.3.0,<0.4.0",
|
|
18
|
+
"langgraph>=1.2.24,<1.3.0",
|
|
19
|
+
"opentelemetry-api>=1.37.0,<2.0.0",
|
|
20
|
+
"pydantic>=2.12.5,<3.0.0",
|
|
21
|
+
"pydantic-settings>=2.12.0,<3.0.0",
|
|
22
|
+
"pyyaml>=6.0.2,<7.0.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[dependency-groups]
|
|
26
|
+
dev = [
|
|
27
|
+
"bandit[toml]>=1.9.4",
|
|
28
|
+
"build>=1.3.0",
|
|
29
|
+
"pre-commit>=4.3.0",
|
|
30
|
+
"pytest>=8.4.0",
|
|
31
|
+
"pytest-asyncio>=1.2.0",
|
|
32
|
+
"pytest-cov>=7.0.0",
|
|
33
|
+
"pytest-mock>=3.15.0",
|
|
34
|
+
"ruff>=0.13.3",
|
|
35
|
+
"ty>=0.0.1a21",
|
|
36
|
+
"types-pyyaml>=6.0.12,<7.0.0",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/agents_builder"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 120
|
|
44
|
+
target-version = "py312"
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint]
|
|
47
|
+
select = ["E", "W", "F", "I", "B", "C4", "UP", "ARG", "SIM"]
|
|
48
|
+
ignore = ["E501", "B008", "B904", "ARG001", "ARG002", "ARG005", "SIM108"]
|
|
49
|
+
|
|
50
|
+
[tool.ruff.lint.isort]
|
|
51
|
+
known-first-party = ["agents_builder"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
addopts = "-ra --strict-markers"
|
|
55
|
+
asyncio_mode = "auto"
|
|
56
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
57
|
+
pythonpath = ["."]
|
|
58
|
+
testpaths = ["tests"]
|
|
59
|
+
|
|
60
|
+
[tool.ty.environment]
|
|
61
|
+
python-version = "3.12"
|
|
62
|
+
|
|
63
|
+
[tool.bandit]
|
|
64
|
+
exclude_dirs = ["tests", ".venv"]
|
|
65
|
+
skips = ["B101"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -ne 1 || -z "$1" || "$1" == -* ]]; then
|
|
5
|
+
echo "Usage: $0 <version>" >&2
|
|
6
|
+
exit 2
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
release_version=$1
|
|
10
|
+
project_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
|
11
|
+
cd "$project_root"
|
|
12
|
+
|
|
13
|
+
uv version --no-sync "$release_version"
|
|
14
|
+
release_version=$(uv version --short)
|
|
15
|
+
build_dir="dist/$release_version"
|
|
16
|
+
|
|
17
|
+
uv build --no-sources --out-dir "$build_dir" --clear
|
|
18
|
+
|
|
19
|
+
shopt -s nullglob
|
|
20
|
+
wheels=("$build_dir"/*.whl)
|
|
21
|
+
sdists=("$build_dir"/*.tar.gz)
|
|
22
|
+
if (( ${#wheels[@]} != 1 || ${#sdists[@]} != 1 )); then
|
|
23
|
+
echo "Expected one wheel and one source distribution in $build_dir" >&2
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
uv publish "${wheels[@]}" "${sdists[@]}"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from langchain_core.tools import BaseTool
|
|
8
|
+
from langgraph.graph.state import CompiledStateGraph
|
|
9
|
+
|
|
10
|
+
from agents_builder.exceptions import (
|
|
11
|
+
MCPNotConfiguredError,
|
|
12
|
+
MCPToolNotFoundError,
|
|
13
|
+
)
|
|
14
|
+
from agents_builder.llm.factory import LLMFactory
|
|
15
|
+
from agents_builder.mixins import FromConfigMixin
|
|
16
|
+
from agents_builder.settings import AgentSettings
|
|
17
|
+
from agents_builder.utils import _cached_mcp_tools, load_class
|
|
18
|
+
|
|
19
|
+
_logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Agent[TConfig: AgentSettings](FromConfigMixin[TConfig], ABC):
|
|
23
|
+
"""A configured agent with a lazy graph, LLM factory, and cached MCP tools."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, config: TConfig) -> None:
|
|
26
|
+
self.config = config
|
|
27
|
+
self._graph: CompiledStateGraph | None = None
|
|
28
|
+
self.init_components()
|
|
29
|
+
_logger.info("Agent initialized")
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def graph(self) -> CompiledStateGraph:
|
|
33
|
+
if self._graph is None:
|
|
34
|
+
_logger.info("Graph not initialized → building graph")
|
|
35
|
+
self._graph = self.build_graph()
|
|
36
|
+
return self._graph
|
|
37
|
+
|
|
38
|
+
async def load_tool(self, mcp_name: str, key: str) -> BaseTool:
|
|
39
|
+
if key in self._tools_by_name:
|
|
40
|
+
return self._tools_by_name[key]
|
|
41
|
+
async with self._tool_lock:
|
|
42
|
+
if key in self._tools_by_name:
|
|
43
|
+
return self._tools_by_name[key]
|
|
44
|
+
mcp = next(
|
|
45
|
+
(m for m in self.config.mcps if m.name == mcp_name),
|
|
46
|
+
None,
|
|
47
|
+
)
|
|
48
|
+
if mcp is None:
|
|
49
|
+
raise MCPNotConfiguredError(tool_key=key)
|
|
50
|
+
tools = await _cached_mcp_tools(
|
|
51
|
+
mcps_fingerprint=f"{mcp.name}:{mcp.url}",
|
|
52
|
+
mcps_config=[mcp],
|
|
53
|
+
)
|
|
54
|
+
for tool in tools:
|
|
55
|
+
self._tools_by_name[tool.name] = tool
|
|
56
|
+
if key not in self._tools_by_name:
|
|
57
|
+
raise MCPToolNotFoundError(
|
|
58
|
+
tool_key=key,
|
|
59
|
+
mcp_name=mcp.name,
|
|
60
|
+
available=list(self._tools_by_name.keys()),
|
|
61
|
+
)
|
|
62
|
+
return self._tools_by_name[key]
|
|
63
|
+
|
|
64
|
+
def init_components(self) -> None:
|
|
65
|
+
self.llm_factory: LLMFactory = load_class(self.config.llm_factory.module_path).from_config(
|
|
66
|
+
self.config.llm_factory
|
|
67
|
+
)
|
|
68
|
+
self._tools_by_name: dict[str, BaseTool] = {}
|
|
69
|
+
self._tool_lock = asyncio.Lock()
|
|
70
|
+
_logger.info("Agent created")
|
|
71
|
+
|
|
72
|
+
def push(self, path: str | None = None) -> None:
|
|
73
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
74
|
+
agent_name = self.__class__.__name__
|
|
75
|
+
filename = f"{agent_name}_graph_{timestamp}.png"
|
|
76
|
+
full_path: Path = Path(path) / filename if path else Path(".") / filename
|
|
77
|
+
png_bytes = self.graph.get_graph().draw_mermaid_png()
|
|
78
|
+
full_path.write_bytes(png_bytes)
|
|
79
|
+
_logger.info(f"Graph saved locally at {full_path}")
|
|
80
|
+
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def build_graph(self) -> CompiledStateGraph: ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CONFIG_PATH = "/config/config.yaml"
|