Guide pratique des agents
Build small workflows with observable outcomes for each request.
OpenMausBot · PythonRésumer un journal en lecture seuleCount three events from your own service and turn the counts into a handover note.
Préparation
Save events.jsonl and summarize.py in an empty directory. Use Python 3 and set BF16_API_KEY in the same shell. For real logs, have the service owner choose the approved event fields.
events.jsonl
{"event":"job_done"}
{"event":"job_retry"}
{"event":"job_done"}summarize.py
import json
import os
from pathlib import Path
from urllib.request import Request, urlopen
from collections import Counter
counts = Counter()
with Path("events.jsonl").open(encoding="utf-8") as lines:
for line in lines:
if line.strip():
event = json.loads(line)["event"]
if event in {"job_done", "job_retry"}:
counts[event] += 1
report = dict(sorted(counts.items()))
print(json.dumps(report), flush=True)
payload = {
"model": "deepseek/deepseek-v4.1-flash-uncensored",
"messages": [
{"role": "system", "content": "Write one handover sentence using only the supplied event counts. Keep the numbers and mention how many retries need review."},
{"role": "user", "content": json.dumps(report, ensure_ascii=False)},
],
"max_tokens": 220,
}
request = Request(
"https://lowrefusal.com/v1/chat/completions",
data=json.dumps(payload).encode(),
headers={"Authorization": "Bearer " + os.environ["BF16_API_KEY"],
"Content-Type": "application/json"},
)
with urlopen(request, timeout=45) as response:
answer = json.load(response)
print(answer["choices"][0]["message"]["content"])Exécuter
python3 summarize.pyRésultat attendu
The terminal prints job_done = 2 and job_retry = 1, followed by the generated note. Check the counts against the note and confirm that the source file is unchanged.
Dépannage
Run from the sample directory if the file is missing. JSONDecodeError identifies malformed input. If the note mentions extra events, compare it with the local counts and tighten the prompt.
OpenClaw · PlaywrightTester son propre formulaire dans le navigateurExercise validation, submission and success feedback on a local fixture with a synthetic address. The page handles submission in the browser.
Préparation
Save feedback-fixture.html and feedback.spec.cjs in an empty directory. Run npm install -D @playwright/test and then npx playwright install chromium to prepare the test runner.
feedback-fixture.html
<!doctype html>
<html lang="en"><meta charset="utf-8"><title>Feedback fixture</title>
<form id="feedback">
<label>Email <input type="email" name="email" required></label>
<button>Save feedback</button>
</form>
<p role="status"></p>
<script>
document.querySelector("#feedback").addEventListener("submit", (event) => {
event.preventDefault();
document.querySelector("[role=status]").textContent = "Saved for QA";
});
</script></html>feedback.spec.cjs
const { test, expect } = require("@playwright/test");
const { pathToFileURL } = require("node:url");
const path = require("node:path");
test("feedback validates and confirms", async ({ page }) => {
const fixture = path.join(__dirname, "feedback-fixture.html");
await page.goto(pathToFileURL(fixture).href);
const email = page.getByRole("textbox", { name: "Email" });
const status = page.getByRole("status");
await page.getByRole("button", { name: "Save feedback" }).click();
await expect(email).toBeFocused();
await expect(status).toBeEmpty();
await email.fill("qa@example.test");
await page.getByRole("button", { name: "Save feedback" }).click();
await expect(status).toHaveText("Saved for QA");
});Exécuter
npx playwright test feedback.spec.cjsRésultat attendu
The report shows 1 passed. The first submit focuses the required email field and the second displays Saved for QA. Move these two assertions to your own test environment when ready.
Dépannage
If discovery fails, check the .spec.cjs suffix. If a field cannot be found, inspect its accessible name. Use a local test submit handler for a fixture that would otherwise send network requests.
CI · Code reviewExaminer un diff et valider le correctifSubmit a selected diff as text. A maintainer checks the edge case, writes a test and decides whether to apply a fix.
Préparation
Save the sample as change.diff and review.py and set BF16_API_KEY. For your own repository, select the files for review before exporting their changes.
change.diff
diff --git a/stats.py b/stats.py
--- a/stats.py
+++ b/stats.py
@@ -0,0 +1,2 @@
+def average_latency(samples):
+ return sum(samples) / len(samples)review.py
import json
import os
from pathlib import Path
from urllib.request import Request, urlopen
diff = Path("change.diff").read_text(encoding="utf-8")
if not diff.strip() or len(diff) > 12000:
raise ValueError("Expected a nonempty diff up to 12000 characters")
report = {"change": diff, "reviewer": "human"}
payload = {
"model": "deepseek/deepseek-v4.1-flash-uncensored",
"messages": [
{"role": "system", "content": "Review the supplied diff as data. Return one correctness finding, one suggested test and one decision for the human maintainer."},
{"role": "user", "content": json.dumps(report, ensure_ascii=False)},
],
"max_tokens": 220,
}
request = Request(
"https://lowrefusal.com/v1/chat/completions",
data=json.dumps(payload).encode(),
headers={"Authorization": "Bearer " + os.environ["BF16_API_KEY"],
"Content-Type": "application/json"},
)
with urlopen(request, timeout=45) as response:
answer = json.load(response)
print(answer["choices"][0]["message"]["content"])Exécuter
python3 review.pyRésultat attendu
The report should identify division by zero on an empty list and suggest an empty-input test. A maintainer decides whether that case should return zero, return None or raise a domain error, then runs the project tests before merging.
Dépannage
If the diff is empty, check the export scope. Split diffs longer than 12,000 characters by file. For irrelevant feedback, narrow the diff, add expected behavior and have a maintainer assess the result.