Skip to content

Commit 90ad15f

Browse files
committed
readme simplify
1 parent 1a2213f commit 90ad15f

1 file changed

Lines changed: 36 additions & 26 deletions

File tree

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,48 @@ skill = Skill(
134134
- Children run in a fresh `SkillContext` (via `run_skill`), so they don't
135135
see the outer trace. Pass data through `entry` if needed.
136136

137-
## Static validation
137+
## `ctx.trace` — cross-step access by name
138138

139-
`check_skill` catches trace-key typos and forward references at definition
140-
time via AST analysis:
139+
```python
140+
from tk.llmbda import Skill, SkillContext, run_skill
141+
142+
def extract(ctx: SkillContext) -> str:
143+
return ctx.entry["text"].upper()
144+
145+
def summarize(ctx: SkillContext) -> str:
146+
return f"extracted: {ctx.trace['extract'].value}"
147+
148+
skill = Skill(name="pipe", steps=[
149+
Skill("extract", fn=extract),
150+
Skill("summarize", fn=summarize),
151+
])
152+
result = run_skill(skill, text="hello")
153+
# result.value == "extracted: HELLO"
154+
```
155+
156+
Use `ctx.trace.get("key")` for optional lookups; missing keys raise an
157+
informative `KeyError`.
158+
159+
## `iter_skill` — streaming / early exit
141160

142161
```python
143-
from tk.llmbda import check_skill
162+
from tk.llmbda import Skill, iter_skill
144163

145-
issues = check_skill(skill)
146-
# ["'bad_step' references undeclared trace key 'typo'"]
164+
skill = Skill(name="s", steps=[step_a, step_b, step_c])
165+
for name, result in iter_skill(skill, {"x": 1}):
166+
print(name, result.value)
167+
if result.resolved:
168+
break
147169
```
148170

149-
- Validates orchestrator children as a separate scope.
150-
- Checks `ctx.trace["key"]` and `ctx.trace.get("key")` patterns.
151-
152-
## Concepts
153-
154-
- **`Skill`** — recursive composition primitive. Leaf (`fn`), composite (`steps`), or orchestrator (`fn` + `steps`).
155-
- **`StepResult.resolved`** — defaults to `False`; steps fall through. Set `True` to short-circuit.
156-
- **`StepResult.resolved_by`** — inner resolution path as `tuple[str, ...]`. Orchestrators propagate it from nested `run_skill` calls; `SkillResult.resolved_by` prepends the step name, building a hierarchical path like `("orchestrator", "inner_step")`.
157-
- **Implicit `StepResult`** — step fns can return any value; non-`StepResult` returns are wrapped as `StepResult(value=x)`. Use explicit `StepResult` for `resolved`, `metadata`, or `resolved_by`.
158-
- **Bare callables in `steps`**`steps=[my_fn]` auto-wraps to `Skill(name=fn.__name__, fn=my_fn)`. Use explicit `Skill(name, fn=...)` for custom names.
159-
- **`run_skill` / `iter_skill` kwargs**`run_skill(skill, name="λ")` is sugar for `run_skill(skill, {"name": "λ"})`.
160-
- **`ctx.prev`** — most recently executed step's `StepResult`. Starts as `ROOT` (`value=None`).
161-
- **`ctx.trace`** — dict of all prior results keyed by step name. Raises informative `KeyError` on miss; use `.get()` for optional lookups.
162-
- **`ctx.entry`** — the original input passed to `run_skill`.
163-
- **`@lm(model, system_prompt=...)`** — binds model at decoration time. Decorated fn is `(ctx, call)` for leaves or `(ctx, steps, call)` for orchestrators; `call` prepends `system_prompt`.
164-
- **`Skill.description`** — human-readable summary; falls back to fn docstring. Separate from `@lm` system prompts (read those via `fn.lm_system_prompt`).
165-
- **`StepResult.metadata`** — auxiliary context: reasons, raw provider output, confidence.
166-
- **`iter_skill`** — same as `run_skill` but yields `(name, result)` per step for streaming or early exit.
167-
- **`check_skill`** — static validation of trace-key references. Catches typos and forward refs.
168-
- **Test re-binding**`lm(fake)(my_step.__wrapped__)` re-decorates with a different model.
171+
## Test re-binding
172+
173+
```python
174+
from tk.llmbda import lm
175+
176+
fake_model = lambda *, messages, **kw: "2025-01-15"
177+
testable = lm(fake_model)(extract_date.__wrapped__)
178+
```
169179

170180
## Examples
171181

0 commit comments

Comments
 (0)