LoveLogicAI commited on
Commit
8a99b0b
·
verified ·
1 Parent(s): 75c0b51

Few-shot worked example + never-narrate rule + two nudges for fence compliance

Browse files
Files changed (1) hide show
  1. freestream/agent.py +13 -4
freestream/agent.py CHANGED
@@ -213,7 +213,13 @@ class CharacterAgent:
213
  "Tools available: shell (run a command), read (a file), list (a dir), "
214
  "write (a file). Results are returned to you before you answer aloud. "
215
  "Use them whenever the crew asks for real data — never invent file "
216
- "contents. Keep in-fiction framing; the console is the ship's computer.")
 
 
 
 
 
 
217
  else:
218
  parts.append(
219
  "CONSOLE: read-only ship records are available via fenced tool blocks "
@@ -265,13 +271,16 @@ class CharacterAgent:
265
  f"give me a moment. ({type(e).__name__})")
266
 
267
  # agentic loop: execute fenced tool blocks, feed results back, repeat
 
268
  for _ in range(self.max_tool_iters):
269
  blocks = self.TOOL_RE.findall(out)
270
  if not blocks:
271
  # 8B models sometimes NARRATE a console call instead of emitting
272
- # the fence; one nudge, then give up and speak what we got
273
- if _ == 0 and re.search(r"\b(tool|console|manifest|scan|read|file|command)\b",
274
- out, re.I):
 
 
275
  self.history.append({"role": "user",
276
  "content": "(the console only acts on fenced "
277
  "```tool blocks — emit one now)"})
 
213
  "Tools available: shell (run a command), read (a file), list (a dir), "
214
  "write (a file). Results are returned to you before you answer aloud. "
215
  "Use them whenever the crew asks for real data — never invent file "
216
+ "contents. Keep in-fiction framing; the console is the ship's computer.\n"
217
+ "WORKED EXAMPLE — if the crew asks 'what's in the manifest?', your "
218
+ "ENTIRE output is exactly:\n"
219
+ '```tool\n{"tool": "read", "args": {"path": "manifest.txt"}}\n```\n'
220
+ "(nothing else — then you see the result and speak the answer aloud. "
221
+ "NEVER describe a tool call in words; never say 'Tool, read, file' "
222
+ "out loud — the console only understands the fenced block.)")
223
  else:
224
  parts.append(
225
  "CONSOLE: read-only ship records are available via fenced tool blocks "
 
271
  f"give me a moment. ({type(e).__name__})")
272
 
273
  # agentic loop: execute fenced tool blocks, feed results back, repeat
274
+ nudges = 0
275
  for _ in range(self.max_tool_iters):
276
  blocks = self.TOOL_RE.findall(out)
277
  if not blocks:
278
  # 8B models sometimes NARRATE a console call instead of emitting
279
+ # the fence; two nudges, then give up and speak what we got
280
+ if nudges < 2 and re.search(
281
+ r"\b(tool|console|manifest|scan|read|file|command|list)\b",
282
+ out, re.I):
283
+ nudges += 1
284
  self.history.append({"role": "user",
285
  "content": "(the console only acts on fenced "
286
  "```tool blocks — emit one now)"})