Skip to content

Commit cfd2d7a

Browse files
committed
chore: add basic logging setup (MICRO_AGENT_LOG) to CLI/server; document health endpoints and logging in README
1 parent fd06b7e commit cfd2d7a

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ micro-agent replay --path traces/<id>.jsonl --index -1
7272
- Endpoint: `POST /ask`
7373
- Request JSON: `{ "question": "...", "max_steps": 6, "use_tool_calls": bool? }`
7474
- Response JSON: `{ "answer": str, "trace_id": str, "trace_path": str, "steps": [...], "usage": {...}, "cost_usd": number }`
75+
- Health: `GET /healthz` (ok), `GET /health` (provider/model), `GET /version` (package version)
7576

7677
Example:
7778
```bash
@@ -100,6 +101,10 @@ curl -s http://localhost:8000/trace/$TID | jq .
100101
micro-agent replay --path traces/$TID.jsonl --index -1
101102
```
102103
104+
## Logging
105+
- Controlled via `MICRO_AGENT_LOG` (debug|info|warning|error). Default: `INFO`.
106+
- Applies to both CLI and server.
107+
103108
## Tools
104109
- Built-ins live in `micro_agent/tools.py`:
105110
- `calculator`: safe expression evaluator. Supports `+ - * / ** % // ( )` and `!` via rewrite to `fact(n)`.

micro_agent/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .agent import MicroAgent
77
from .runtime import dump_trace, new_trace_id
88
from .costs import estimate_prediction_cost
9+
from .logging_setup import setup_logging
910

1011
console = Console()
1112

@@ -33,6 +34,7 @@ def main():
3334

3435
args = parser.parse_args()
3536

37+
setup_logging()
3638
configure_lm()
3739
if args.cmd == "replay":
3840
from rich.syntax import Syntax

micro_agent/logging_setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
import logging
3+
import os
4+
5+
6+
def setup_logging() -> None:
7+
"""Configure basic logging for CLI/server usage.
8+
9+
Controlled via env var MICRO_AGENT_LOG (debug|info|warning|error).
10+
Defaults to INFO. No-op if already configured.
11+
"""
12+
if logging.getLogger().handlers:
13+
return
14+
level_str = os.getenv("MICRO_AGENT_LOG", "INFO").upper()
15+
level = getattr(logging, level_str, logging.INFO)
16+
fmt = "%(asctime)s %(levelname)s %(name)s: %(message)s"
17+
logging.basicConfig(level=level, format=fmt)
18+

micro_agent/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .config import configure_lm
99
from .agent import MicroAgent
1010
from .runtime import dump_trace, new_trace_id
11+
from .logging_setup import setup_logging
1112

1213
app = FastAPI(title="DSPy Micro Agent")
1314
app.add_middleware(
@@ -31,6 +32,7 @@ class AskResponse(BaseModel):
3132
usage: dict | None = None
3233
cost_usd: float | None = None
3334

35+
setup_logging()
3436
configure_lm()
3537
_agent = MicroAgent()
3638

0 commit comments

Comments
 (0)