Skip to content

Commit 0bc97f7

Browse files
authored
Merge pull request #20 from Accenture/feature/docs-site
Documentation site - Composable for Python (mkdocs-material, engine theme) + CI workflow
2 parents 5424f61 + a8ebde2 commit 0bc97f7

19 files changed

Lines changed: 1421 additions & 0 deletions

‎.github/workflows/ci.yml‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: ci
2+
3+
# The wrapper's quality gates (pytest, ruff, basedpyright) plus the strict
4+
# documentation build, then gh-pages publication on push to main - the same
5+
# verify/deploy split as the engine repo's docs workflow.
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.10' # the supported floor
23+
- name: Install package with dev extras
24+
run: pip install -e '.[dev]' basedpyright
25+
- name: Lint (ruff)
26+
run: ruff check .
27+
- name: Type check (basedpyright)
28+
run: basedpyright
29+
- name: Unit tests
30+
run: pytest -q
31+
32+
docs:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-python@v5
37+
with:
38+
python-version: '3.x'
39+
- name: Install MkDocs
40+
run: pip install mkdocs-material
41+
- name: Build docs (strict)
42+
run: mkdocs build --strict
43+
44+
deploy-docs:
45+
# Publish to gh-pages only on push to main or manual dispatch, after both gates pass.
46+
if: github.event_name != 'pull_request'
47+
needs: [test, docs]
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
concurrency:
52+
group: docs-deploy
53+
cancel-in-progress: false
54+
steps:
55+
- uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
- uses: actions/setup-python@v5
59+
with:
60+
python-version: '3.x'
61+
- name: Install MkDocs
62+
run: pip install mkdocs-material
63+
- name: Build (strict) and deploy to gh-pages
64+
run: mkdocs gh-deploy --force --strict

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ uv.lock
4343
.aider.tags.cache*
4444
review-scratch/
4545
*.py[cod]
46+
47+
# mkdocs build output
48+
site/

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 0.1.0 (unreleased)
44

5+
- Documentation site (mkdocs-material, the engine repo's theme): the three-layer theme
6+
reference, rationale/design foundations, function-writing patterns, flow and
7+
knowledge-graph join chapters, a one-page AI agent guide with llms.txt, and
8+
configuration/HTTP references - published to
9+
https://accenture.github.io/mercury-python/ by the new CI workflow, which also runs
10+
the three quality gates (pytest, ruff, basedpyright) on every push and pull request.
511
- Host polish for engine parity: `GET /` serves the engines' minimal index page linking
612
the actuator endpoints (embedded - no static file service by design); actuator JSON
713
responses are pretty-printed (the engines' default-serializer presentation); unknown

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Orchestration deliberately stays in the engines. Functions written here are addr
2020
route name through the engines' declarative `yaml.event.over.http` map, so a flow or a
2121
graph task calls a Python function exactly as if it were local.
2222

23+
**Documentation:** <https://accenture.github.io/mercury-python/> — including the
24+
[AI Agent Guide](https://accenture.github.io/mercury-python/guides/ai-agent-guide/)
25+
for deterministic function generation.
26+
2327
> **Status: pre-release.** This repository was repurposed in August 2026 for the polyglot
2428
> initiative. The legacy Mercury language-pack implementation remains available in the git
2529
> history.

‎docs/css/extra.css‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Mercury Composable docs — small overrides on the Material theme.
2+
*
3+
* Reference tables should wrap long inline-code tokens (package and type
4+
* names like org.platformlambda.core.annotations) instead of forcing the
5+
* whole table to scroll horizontally.
6+
*/
7+
8+
.md-typeset table:not([class]) td,
9+
.md-typeset table:not([class]) th {
10+
vertical-align: top;
11+
}
12+
13+
/* Break only genuinely long tokens, and only as a last resort. Unlike
14+
* word-break / overflow-wrap:anywhere, this does NOT shrink a column below
15+
* its longest word — short words like "String" are never split mid-word. */
16+
.md-typeset table:not([class]) td code,
17+
.md-typeset table:not([class]) th code {
18+
overflow-wrap: break-word;
19+
white-space: normal;
20+
}

‎docs/guides/ai-agent-guide.md‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: AI Agent Guide
3+
summary: The complete authoring grammar for Python polyglot functions on one page -
4+
contract, registration, config keys, endpoints and error rules, for deterministic generation.
5+
audience: [ai-agent]
6+
keywords: [ai agent, grammar, contract, deterministic, preload, postoffice]
7+
---
8+
9+
# AI Agent Guide
10+
11+
**Purpose: generate a correct Python polyglot function from this page alone.**
12+
Humans: the narrative versions live in [Function Writing Patterns](function-patterns.md)
13+
and the [join chapters](join-event-script.md). Orchestration (flows, graphs) is
14+
authored on the engine — use the
15+
[engine AI guides](https://accenture.github.io/mercury-composable/guides/ai-developer-guide/).
16+
17+
## Pre-write checklist
18+
19+
1. Route name: lowercase `[a-z0-9._-]`, at least one period. Example: `order.enrich`.
20+
2. Handler style: wraps blocking library (`requests`, NumPy, DB driver) → plain `def`;
21+
asyncio I/O or calls sibling functions → `async def`.
22+
3. Function is stateless. State belongs to the calling flow/graph.
23+
4. Orchestration-shaped logic (sequencing, retries, branching) → STOP; author an
24+
Event Script flow or MiniGraph graph on the engine instead.
25+
26+
## The contract
27+
28+
```python
29+
from mercury_composable import AppException, Body, PostOffice, annotate_trace, \
30+
get_logger, get_trace, platform, preload
31+
32+
log = get_logger(__name__)
33+
34+
@preload(route="order.enrich", instances=10) # private=True -> in-app only
35+
def handler(headers: dict[str, str], body: Body): # or: async def
36+
# 1. validate; intentional errors = AppException(status, message)
37+
if not isinstance(body, dict) or not isinstance(body.get("id"), str):
38+
raise AppException(400, "missing 'id'")
39+
# 2. work (blocking is safe in plain def - executor thread)
40+
# 3. optional telemetry
41+
annotate_trace("source", "python") # rides back on the reply
42+
# 4. return the reply body (or an EventEnvelope for status/header control)
43+
return {"id": body["id"], "enriched": True}
44+
45+
if __name__ == "__main__":
46+
platform.run()
47+
```
48+
49+
Rules:
50+
51+
- `headers: dict[str, str]`; `body: Body` = `None|bool|int|float|str|bytes|list|dict`.
52+
- Return value = reply body. Return `EventEnvelope` only when setting status/headers.
53+
- `raise AppException(status, message)` → envelope status + message (portable error).
54+
Unexpected exception → 500 + message + stack. Never return HTTP-shaped dicts.
55+
- `get_trace()` → `TraceInfo(trace_id, trace_path, cid)` or `None`.
56+
- Reserved inbound header `my_correlation_id` = the caller's business correlation id
57+
(read-only). Never send headers named `my_*` or `x-event-api`.
58+
59+
## Composition (calling other functions)
60+
61+
```python
62+
# async handler:
63+
reply = await PostOffice().request("other.route", body={...}, timeout_ms=5000)
64+
# plain-def handler (sync bridge; blocks only this worker thread):
65+
reply = PostOffice().request_sync("other.route", body={...}, timeout_ms=5000)
66+
# drop-n-forget twins: send / send_sync -> 202 ack envelope
67+
# remote peer or engine:
68+
async with PostOffice(endpoint="http://host:8085/api/event") as po: ...
69+
```
70+
71+
- `request_sync` on the event loop → RuntimeError (use `await request()`).
72+
- `request_sync` outside a hosted function → RuntimeError (use `asyncio.run(...)`).
73+
- Always check `reply.get_status()`; errors are envelopes, not exceptions.
74+
- Local calls reach `private=True` routes; the wire cannot (403).
75+
76+
## Run + configure
77+
78+
```bash
79+
mercury-serve app.py # config: resources/application.yml
80+
mercury-serve app.py -Dkey=value # runtime override (engine syntax)
81+
```
82+
83+
Well-known keys (full table: [Configuration Reference](configuration-reference.md)):
84+
`application.name`, `rest.server.port` (default 8085), `log.format`
85+
(text|json|compact), `log.level`, `info.app.version`, `info.app.description`,
86+
`show.env.variables`, `show.application.properties`,
87+
`mandatory.health.dependencies`, `optional.health.dependencies`.
88+
89+
## Health check function (engine interface contract)
90+
91+
```python
92+
@preload(route="my.health", instances=5, private=True)
93+
async def health(headers: dict[str, str], _body: Body):
94+
if headers.get("type") == "info":
95+
return {"service": "my.dependency", "href": "http://backend"}
96+
return "my.dependency is running fine" # non-200 reply marks it DOWN
97+
```
98+
99+
List the route in `mandatory.health.dependencies` (or `optional.…`).
100+
101+
## HTTP surface (served by the host, no code needed)
102+
103+
`POST /api/event` (envelope wire) · `GET /` `/info` `/info/routes` `/env` `/health`
104+
`/livenessprobe`. Shapes: [HTTP Surface Reference](http-surface-reference.md).
105+
106+
## Engine-side wiring (for completeness; authored on the engine)
107+
108+
```yaml
109+
# application.properties: yaml.event.over.http=classpath:/event-over-http.yaml
110+
event.http:
111+
- route: 'order.enrich'
112+
target: 'http://python-host:8086/api/event'
113+
```
114+
115+
Flow task `process: 'order.enrich'` or graph node
116+
`{"skill": "graph.task", "task": "order.enrich", ...}` (engines ≥ v4.11.11 for
117+
graph.task). Details: [Join an Event Script Flow](join-event-script.md) ·
118+
[Join a Knowledge Graph](join-knowledge-graph.md).
119+
120+
## DO / DON'T
121+
122+
| DO | DON'T |
123+
|----|-------|
124+
| plain `def` for blocking libraries | block inside `async def` |
125+
| `AppException` for intentional errors | return `{"status": 400, ...}` dicts |
126+
| keep functions stateless | cache business state in module globals |
127+
| compose one or two leaf helpers | re-implement flows/retries in Python |
128+
| let deadlines fail fast (408 envelope) | swallow timeouts and hoard work |
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Configuration, Logging & Actuators
3+
summary: The engines' operational conventions in Python - resources folder, -D overrides,
4+
three log formats, actuator endpoints and Kubernetes probes.
5+
audience: [developer, operator]
6+
keywords: [configuration, resources, log format, actuator, health, kubernetes, livenessprobe]
7+
---
8+
9+
# Configuration, Logging & Actuators
10+
11+
*Write functions: run them the way engine apps run.*
12+
13+
> **At a glance**
14+
>
15+
> - **What** — one configuration style, one log presentation, one operational surface
16+
> across Java, Rust, Python and Node.js apps.
17+
> - **For** developers wiring an app and operators monitoring a polyglot estate.
18+
19+
## Configuration — the engines' conventions
20+
21+
Configuration lives in the `resources` folder (`resources/application.yml`, `.yaml`
22+
or `.properties`), in the working directory or next to the application file. Values
23+
support `${ENV_VAR:default}` substitution; `-Dkey=value` command-line arguments are
24+
runtime overrides checked first on every read — the same syntax as the Java engine's
25+
JVM system properties and the Rust port's `-D` arguments:
26+
27+
```bash
28+
mercury-serve app.py -Drest.server.port=8090 -Dlog.format=compact
29+
```
30+
31+
See the worked sample
32+
[`examples/resources/application.yml`](https://github.com/Accenture/mercury-python/blob/main/examples/resources/application.yml)
33+
and the full key table in the [Configuration Reference](configuration-reference.md).
34+
35+
## Logging — one aggregation, three presentations
36+
37+
Log lines follow the Java reference engine's pattern, so a polyglot installation reads
38+
one way in the aggregator:
39+
40+
```text
41+
2026-08-24 10:15:30.123 INFO my_app:42 - Loaded PUBLIC hello.python, instances=10
42+
```
43+
44+
`log.format` carries the engines' three presentations: `text` (default), `json`
45+
(pretty-printed) and `compact` (single-line JSONL for log aggregators). The level
46+
comes from the `LOG_LEVEL` environment variable when set, else `log.level`.
47+
48+
## Actuators — the engines' operational surface
49+
50+
The host serves the engines' endpoints on the same port as `/api/event`:
51+
52+
| Endpoint | Purpose |
53+
|----------|---------|
54+
| `GET /` | minimal index page linking the endpoints below |
55+
| `GET /info` | app identity, runtime, origin id, start time, uptime |
56+
| `GET /info/routes` | registered routes split by visibility, with instance counts |
57+
| `GET /env` | selected environment variables and configuration parameters (opt-in lists) |
58+
| `GET /health` | dependency health checks — `UP` (HTTP 200) or `DOWN` (HTTP 400) |
59+
| `GET /livenessprobe` | `OK` while the last health outcome was good, else HTTP 400 |
60+
61+
JSON responses are pretty-printed (the engines' default-serializer presentation) with
62+
`application/json; charset=utf-8`; unknown paths answer the engines' error shape —
63+
see the [HTTP Surface Reference](http-surface-reference.md).
64+
65+
### Health check functions — the engines' interface contract
66+
67+
A health check is a normal registered function (usually private) listed in
68+
`mandatory.health.dependencies` / `optional.health.dependencies`. The actuator calls
69+
it through the event bus, first with header `type=info` (an advisory identity map
70+
merged into its dependency entry), then with `type=health` (a status text or map; a
71+
non-200 reply marks the dependency down):
72+
73+
```python
74+
@preload(route="demo.health", instances=5, private=True)
75+
async def health_check(headers: dict[str, str], _body: Body):
76+
if headers.get("type") == "info":
77+
return {"service": "demo.service", "href": "http://127.0.0.1"}
78+
return "demo.service is running fine"
79+
```
80+
81+
Optional dependencies never change the overall status; mandatory ones decide
82+
`UP`/`DOWN`, and the most recent outcome drives `/livenessprobe`.
83+
84+
## Kubernetes wiring
85+
86+
```yaml
87+
livenessProbe:
88+
httpGet: { path: /livenessprobe, port: 8086 }
89+
readinessProbe:
90+
httpGet: { path: /health, port: 8086 }
91+
```
92+
93+
The pod presents exactly like an engine pod — one dashboard shape for the whole
94+
polyglot estate.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Configuration Reference
3+
summary: Every well-known configuration key, the resolution order, and the substitution syntax.
4+
audience: [developer, operator, ai-agent]
5+
keywords: [configuration, reference, keys, substitution, overrides]
6+
---
7+
8+
# Configuration Reference
9+
10+
*Reference: the complete key table.*
11+
12+
## Resolution
13+
14+
1. `-Dkey=value` command-line overrides (and programmatic `AppConfig.set`) — checked
15+
first on every read, the engines' `f:setConfig` analog.
16+
2. The configuration file: `resources/application.yml` | `.yaml` | `.properties`, in
17+
the working directory or next to the application file, or `--config <path>`.
18+
3. `${ENV_VAR:default}` substitution inside values: environment first, then a base
19+
configuration key of that name, then the default.
20+
21+
## Well-known keys (shared with the engines)
22+
23+
| Key | Meaning | Default |
24+
|-----|---------|---------|
25+
| `application.name` | application identity in logs, `/info` and `/health` | `application` |
26+
| `rest.server.port` | Event API + actuator port | `8085` |
27+
| `log.format` | `text`, `json` (pretty-printed) or `compact` (single-line JSONL) | `text` |
28+
| `log.level` | log level; the `LOG_LEVEL` environment variable wins | `INFO` |
29+
| `info.app.version` | version reported by `/info` | package version |
30+
| `info.app.description` | description reported by `/info` | `application.name` |
31+
| `show.env.variables` | opt-in list of environment variables shown by `/env` | (empty) |
32+
| `show.application.properties` | opt-in list of configuration keys shown by `/env` | (empty) |
33+
| `mandatory.health.dependencies` | routes of health check functions that decide `/health` | (empty) |
34+
| `optional.health.dependencies` | health check routes reported but never affecting status | (empty) |
35+
36+
List-valued keys accept a comma/space-separated string (engine syntax) or a YAML list.
37+
38+
## Programmatic access
39+
40+
```python
41+
from mercury_composable import app_config
42+
43+
config = app_config()
44+
port = config.get("rest.server.port", 8085)
45+
name = config.get_property("application.name", "application")
46+
config.set("feature.flag", "on") # runtime override, checked first
47+
```

0 commit comments

Comments
 (0)