codegen: move bridge specifics into the catalog
Bridge specifics (service, base-URL config var, auth header/token var, config-var docs, endpoints with error shapes) now live in BridgeInfo and render through describe_bridges(), which is injected into body, retry, regen, elicitation, and testgen prompts. SKILL.md/TESTGEN.md carry only the generic pattern. - regen prompt regains the catalog (was a dangling reference) - elicitation integration hint rides body/retry/regen as an advisory - top-level simplex_bridge_token config var; bootstrap syncs it - simplex seeds read the token and send X-Semif-Token when set
This commit is contained in:
1 parent
d0df6f16c4
commit
98ec4ee5e2
19 files changed
+324
-89
No files matched your search
@@ -14,8 +14,11 @@ Two boundaries matter:
|
||||
own processes (`python -m semif_agent.cli bridge`) against their own service
|
||||
daemons/profiles. This isolation is non-negotiable (see AGENTS.md).
|
||||
- **The catalog is visible to codegen.** `describe_bridges()` is injected into
|
||||
the code-generation prompts so the model knows which real services it may
|
||||
build against and how to reach them.
|
||||
every code-generation prompt (body, retry, regen, elicitation, testgen) and is
|
||||
the single source of bridge specifics: the model learns which real services it
|
||||
may build against, each one's base-URL config var, auth header/token var,
|
||||
config-var docs, and its endpoints with request/response/error shapes. SKILL.md
|
||||
and TESTGEN.md carry only the generic pattern.
|
||||
"""
|
||||
|
||||
from .base import BridgeInfo, BridgeService
|
||||
|
||||
@@ -34,6 +34,13 @@ class BridgeInfo:
|
||||
endpoints: tuple[str, ...] = ()
|
||||
#: Other `ctx.config` keys a body built on this bridge may read.
|
||||
config_vars: tuple[str, ...] = field(default=())
|
||||
#: One-line semantic description per config var: `(name, description)`.
|
||||
#: Every entry in `config_vars` must be documented here.
|
||||
config_var_docs: tuple[tuple[str, str], ...] = ()
|
||||
#: Optional shared-secret header the bridge enforces when its token is set
|
||||
#: (e.g. `X-Semif-Token`), and the top-level `ctx.config` var holding it.
|
||||
auth_header: str = ""
|
||||
auth_config_var: str = ""
|
||||
|
||||
|
||||
class BridgeService(ABC):
|
||||
|
||||
@@ -33,24 +33,37 @@ def known_infos() -> list[BridgeInfo]:
|
||||
def describe_bridges() -> str:
|
||||
"""A prompt block describing every available bridge service.
|
||||
|
||||
Injected into the skill-body and elicitation prompts so codegen knows which
|
||||
real services it may build a skill against, how to reach each one, and which
|
||||
`ctx.config` variable carries its URL. Static — no bridge needs to be
|
||||
running or enabled.
|
||||
Injected into the skill-body, retry, regen, elicitation, and testgen
|
||||
prompts so codegen knows which real services it may build a skill against,
|
||||
how to reach and authenticate to each one, and which `ctx.config` variables
|
||||
carry its URL, token, and other values. This is the single source of bridge
|
||||
specifics — SKILL.md/TESTGEN.md carry only the generic pattern. Static: no
|
||||
bridge needs to be running or enabled.
|
||||
"""
|
||||
lines = [
|
||||
"Available bridge services (call these over HTTP with urllib.request; "
|
||||
"never speak a service's native protocol directly):",
|
||||
"never speak a service's native protocol directly; read every value "
|
||||
"from ctx.config):",
|
||||
]
|
||||
for info in known_infos():
|
||||
lines.append(f"- {info.name}: {info.description}")
|
||||
lines.append(f" config var: {info.url_config_var}")
|
||||
lines.append(f"- {info.name} (service: {info.service}): {info.description}")
|
||||
lines.append(f" base URL config var: {info.url_config_var}")
|
||||
if info.auth_header and info.auth_config_var:
|
||||
lines.append(
|
||||
f" auth: send the value of {info.auth_config_var} in the "
|
||||
f"{info.auth_header} header when it is set"
|
||||
)
|
||||
docs = dict(info.config_var_docs)
|
||||
if info.config_vars:
|
||||
other = [v for v in info.config_vars if v != info.url_config_var]
|
||||
if other:
|
||||
lines.append(f" other config vars: {', '.join(other)}")
|
||||
for endpoint in info.endpoints:
|
||||
lines.append(f" {endpoint}")
|
||||
lines.append(" config vars:")
|
||||
for name in info.config_vars:
|
||||
description = docs.get(name)
|
||||
suffix = f" — {description}" if description else ""
|
||||
lines.append(f" - {name}{suffix}")
|
||||
if info.endpoints:
|
||||
lines.append(" endpoints:")
|
||||
for endpoint in info.endpoints:
|
||||
lines.append(f" - {endpoint}")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
|
||||
@@ -32,18 +32,51 @@ class SimplexBridge(BridgeService):
|
||||
),
|
||||
url_config_var="simplex_bridge_url",
|
||||
endpoints=(
|
||||
"GET /health -> {\"ok\": true} — the bridge is up",
|
||||
"GET /contacts -> {\"contacts\": [{\"id\", \"display_name\"}]}",
|
||||
"GET /inbox -> peek buffered inbound messages (does not consume)",
|
||||
"GET /inbox/next?contact=<id> -> pop the oldest unread message for a "
|
||||
"contact (or any contact) -> {\"message\": {...}|null}",
|
||||
"GET /address -> the agent's SimpleX contact link "
|
||||
"(creates it on first call) -> {\"short_link\", \"full_link\", "
|
||||
"\"created\"}",
|
||||
"GET /health -> 200 {\"ok\": true, \"platform\": \"simplex\"} — the "
|
||||
"bridge is up",
|
||||
"GET /contacts -> 200 {\"contacts\": [{\"id\", \"display_name\"}]} — "
|
||||
"contacts learned from inbound messages",
|
||||
"GET /inbox -> 200 {\"messages\": [{\"id\", \"contact_id\", "
|
||||
"\"display_name\", \"text\", \"received_at\"}]} — peek buffered "
|
||||
"inbound messages; does not consume",
|
||||
"GET /inbox/next?contact=<id> -> 200 {\"message\": {...}|null} — pop "
|
||||
"the oldest unread message (optionally from one contact); null means "
|
||||
"none buffered. The bridge owns the read cursor",
|
||||
"GET /address -> 200 {\"short_link\", \"full_link\", \"created\"} — "
|
||||
"the agent's contact link; creates it on first call. 503 when the "
|
||||
"daemon is not connected, 502 when the lookup fails",
|
||||
"POST /send {\"recipient\": \"<id|display_name>\", \"text\": \"...\"} "
|
||||
"-> {\"ok\", \"contact_id\"}",
|
||||
"-> 200 {\"ok\": true, \"contact_id\": \"<id>\"}; 400 {\"error\": "
|
||||
"\"...\"} on a missing/invalid field or an unknown recipient",
|
||||
"any request -> 401 {\"error\": \"unauthorized\"} when the token is "
|
||||
"configured and the auth header is missing or wrong",
|
||||
),
|
||||
config_vars=("simplex_bridge_url", "simplex_default_contact"),
|
||||
config_vars=(
|
||||
"simplex_bridge_url",
|
||||
"simplex_default_contact",
|
||||
"simplex_bridge_token",
|
||||
),
|
||||
config_var_docs=(
|
||||
(
|
||||
"simplex_bridge_url",
|
||||
"Base URL of the local SimpleX forwarding bridge "
|
||||
"(e.g. http://127.0.0.1:5227); never hardcode it in the body.",
|
||||
),
|
||||
(
|
||||
"simplex_default_contact",
|
||||
"Optional default SimpleX contact (contact id or display name) "
|
||||
"used when the request does not already make the conversation "
|
||||
"clear; leave blank to always choose among senders.",
|
||||
),
|
||||
(
|
||||
"simplex_bridge_token",
|
||||
"Shared secret for the bridge, if one is configured; sent as the "
|
||||
"X-Semif-Token header. Leave blank when the bridge requires no "
|
||||
"auth.",
|
||||
),
|
||||
),
|
||||
auth_header="X-Semif-Token",
|
||||
auth_config_var="simplex_bridge_token",
|
||||
)
|
||||
|
||||
def __init__(self, config: dict | None = None, trace=None, daemon=None):
|
||||
|
||||
+25
-2
@@ -652,6 +652,24 @@ def _requirements_block(requirements: dict[str, str] | None) -> str:
|
||||
return f"Requirements gathered from the product owner:\n{lines}\n"
|
||||
|
||||
|
||||
def _integration_hint_block(draft: SkillDraft) -> str:
|
||||
"""Advisory integration hint from elicitation: service + transport.
|
||||
|
||||
Never overrides the request, requirements, or SKILL.md contract — it only
|
||||
biases the body writer toward the integration the questions were aiming at.
|
||||
"""
|
||||
integration = getattr(draft, "integration", None) or {}
|
||||
service = integration.get("service")
|
||||
transport = integration.get("transport")
|
||||
if not service and not transport:
|
||||
return ""
|
||||
return (
|
||||
"Elicitation pointed at this integration (advisory only: follow the "
|
||||
"request, requirements, and contract if they disagree): "
|
||||
f"service={service or 'unknown'}, transport={transport or 'unknown'}.\n"
|
||||
)
|
||||
|
||||
|
||||
def build_skill_body_prompt(
|
||||
request: Request,
|
||||
category: str,
|
||||
@@ -683,6 +701,7 @@ def build_skill_body_prompt(
|
||||
f"Existing skills in this category: {existing}\n"
|
||||
f"Existing categories:\n{tree_summary(tree)}\n"
|
||||
f"{req_block}"
|
||||
f"{_integration_hint_block(draft)}"
|
||||
f"{describe_bridges()}\n"
|
||||
f"{BODY_DIRECTIVES}"
|
||||
"Write the Python module body now. Reply with ONLY valid Python code "
|
||||
@@ -997,6 +1016,7 @@ def _retry_prompt(
|
||||
f"Skill name: {draft.name}\n"
|
||||
f"Skill description: {draft.description}\n"
|
||||
f"{_requirements_block(requirements)}"
|
||||
f"{_integration_hint_block(draft)}"
|
||||
f"{describe_bridges()}\n"
|
||||
f"{BODY_DIRECTIVES}"
|
||||
"Reply with ONLY valid Python defining `predict` and `act`. No prose, "
|
||||
@@ -1070,7 +1090,7 @@ ELICITATION_EXAMPLES = [
|
||||
"How does it authenticate with the service, and should that credential come from the app's config?",
|
||||
"What does a successful run look like — what should it report back to you?",
|
||||
"If the service is unreachable or refuses the action, should the run fail loudly or record 'could not complete' as the result?",
|
||||
"Should this skill send or read SimpleX messages through the simplex bridge, and if so which conversation (resolved by contact name)?",
|
||||
"Should this skill read or send through one of the available bridge services (see the catalog below), and if so which conversation or target?",
|
||||
]
|
||||
|
||||
|
||||
@@ -1287,7 +1307,8 @@ def build_testgen_base_prompt(
|
||||
user = (
|
||||
f"Skill: {category}.{name}\n"
|
||||
f"Request: {request.text}\n"
|
||||
f"Finished skill body:\n```python\n{skill_code}\n```"
|
||||
f"Finished skill body:\n```python\n{skill_code}\n```\n"
|
||||
f"{describe_bridges()}"
|
||||
)
|
||||
return [
|
||||
{"role": "system", "content": system},
|
||||
@@ -1527,6 +1548,8 @@ def _regen_body_prompt(
|
||||
f"Skill description: {draft.description}\n"
|
||||
f"Evidence:\n{render_evidence(evidence)}\n"
|
||||
f"Previous body:\n```python\n{previous_code}\n```\n"
|
||||
f"{_integration_hint_block(draft)}"
|
||||
f"{describe_bridges()}\n"
|
||||
f"{BODY_DIRECTIVES}"
|
||||
"Reply with ONLY valid Python defining `predict` and `act`. No prose, "
|
||||
"no markdown fences, no JSON."
|
||||
|
||||
@@ -124,7 +124,8 @@ class SkillDraft:
|
||||
`requirements` maps elicitation questions (asked of the human during
|
||||
authoring) to their answers; they are fed to the body-writer so the body
|
||||
reflects the refined product goal. `integration` carries the service and
|
||||
transport the answers point at, so the body writer implements exactly that.
|
||||
transport the answers point at; it is fed to the body writer as an advisory
|
||||
hint only — the SKILL.md contract, request, and requirements still win.
|
||||
"""
|
||||
|
||||
name: str
|
||||
|
||||
Reference in new issue
Block a user