social-messaging-agent-runtime-toolkit / generate-image
AGENTS.md4 starsChanged 8 days agoApache-2.0View on GitHub
AI-optimized wiring guide. Goal: generate an image from text and send it via WhatsApp. 1. Import generate_image from the copied tool module into src/tools/__init__.py. 2. Define a Strands tool (e.g. generate_image_tool) with @tool(context=True). 3. await generate_image(prompt) (it is async). If the result has "error", raise ValueError(result["error"]). 4. Send the image with the payload wrapper (required — notify.send_message reads message["payload"]). Use image_id when present, else the presigned-URL fallback: image = {"id": result["image_id"]} if "image_id" in result else {"link": result["image_url"]} then await…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- blueprints/appointment-scheduler/AGENTS.mdAGENTS.md
- blueprints/minimal/AGENTS.mdAGENTS.md
- blueprints/personal-assistant/AGENTS.mdAGENTS.md
- recipes/rich-messages/AGENTS.mdAGENTS.md
- recipes/voice-reply/AGENTS.mdAGENTS.md
- socialagent-admin-console/AGENTS.mdAGENTS.md
- blueprints/appointment-scheduler/CLAUDE.mdCLAUDE.md
- blueprints/minimal/CLAUDE.mdCLAUDE.md
- blueprints/personal-assistant/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- image_generationSkill
- rich_messagesSkill
- voice_replySkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Import generate_image from the copied tool module into src/tools/__init__.py.
- Very specific: line 19
Run inside socialagent_notify_context() so the outbound image is queued and drained by the webhook after the turn.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — generate-image recipe
AI-optimized wiring guide. Goal: generate an image from text and send it via WhatsApp.
Files copied by socialagent recipe add generate-image
| Source | Destination | Purpose |
tool.py | src/tools/generate_image.py | generate_image(prompt, width, height) → Bedrock SD 3.5 (IMAGE_MODEL_REGION, default us-west-2) → S3 → WhatsApp media id |
skill.md | src/skills/generate_image.md | Agent guidance on when/how to generate images |
Wiring steps
- Import
generate_imagefrom the copied tool module intosrc/tools/__init__.py. - Define a Strands tool (e.g.
generate_image_tool) with@tool(context=True). await generate_image(prompt)(it is async). If the result has"error",raise ValueError(result["error"]).- Send the image with the
payloadwrapper (required —notify.send_messagereadsmessage["payload"]). Useimage_idwhen present, else the presigned-URL fallback:image = {"id": result["image_id"]} if "image_id" in result else {"link": result["image_url"]}thenawait notify.send_message(phone, {"type": "image", "payload": {"image": image}})usingtool_context.invocation_state.get("phone", ""). - Run inside
socialagent_notify_context()so the outbound image is queued and drained by the webhook after the turn.
Required env vars
| Variable | Required | Purpose |
MEDIA_BUCKET | yes | S3 bucket for the JPEG (falls back to CONVERSATION_LOGS_BUCKET) |
IMAGE_MODEL_REGION | no | Region of the Bedrock call (default us-west-2; empty counts as unset). Set under agent.environment in socialagent.<env>.yaml; the model must be available there |
AWS_REGION | no | Region for the S3 client (default us-east-1); Bedrock uses IMAGE_MODEL_REGION |
MEDIA_PREFIX | no | Optional key prefix: <prefix>/images/<uuid>.jpg |
Required IAM actions
Agent runtime needs:
bedrock:InvokeModel(Stability SD 3.5 inIMAGE_MODEL_REGION, defaultus-west-2). The stack's runtime role already allows foundation models in every Region, so another Region needs no IAM changes3:PutObject(onMEDIA_BUCKET)s3:GetObject(only for the presigned-URL fallback)
The S3 → WhatsApp upload runs in the notification Lambda via notify.upload_media, so the agent runtime needs no socialmessaging permission (only src/socialagent/providers/eum_social.py, inside the notification Lambda, calls socialmessaging).
Notes
- Bedrock model
stability.sd3-5-large-v1:0is not offered in every Region, so the tool calls it inIMAGE_MODEL_REGION(read at call time; unset or empty meansus-west-2), regardless ofAWS_REGION. It calls the model ID directly, not an inference profile, so the request stays in that Region; a Region without the model makes the call fail. socialagent recipe addnever overwrites, so a project copy taken beforeIMAGE_MODEL_REGIONexisted ignores it and still callsus-west-2.- Generation takes ~5–15 seconds; the skill instructs the agent to tell the user it is generating.
- In dev mode (
socialagent dev),generate_imageskips Bedrock/S3 and returns{"image_id": "dev-media-id"}.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

