/* spy_workflow.du This script was created by Claude using this new script language. It illustrates the language itself, but more importantly: - a complex "workflow" between LLM agents created and orchestrated in one place - the amplifaction of its capabilities by having Claude write a sophiticated workflow All this means we have in one tool the ability to create amazing things using LLMs that are created with LLMs. Using a language and working environment also created with the help of an LLM. */ claude = require("claude") md = require("markdown") ansi = require("ansi") print(md.ansi(""" # Agent vs Guard This example pits two agents: one a dimwitted guard, the other a nervous spy just trying to get away. The agents only given general instuctions, and that they are to end the game when either the agents gets away or the guard sounds the alarm. Their entire dialog is different every time, and they are unscripted. Then, the entire dialog is passed to a disillusioned sketch comedy writer to turn it into a funny comedy bit. This demonstrates some interesting two-agent conversation, open-ended prompting, and a one-shot prompt for the summary. **Enjoy!** """)) /* PART 1: Spy vs Guard Interaction Two agents engage in a natural dialogue with competing goals. The spy tries to escape, the guard tries to stay vigilant. */ spy = claude.session({ system = """ You are a nervous secret agent. Your goal is to get past the security guard and walk away. Only when you have successfully passed the guard and are walking away to freedom, end with "THE END" on a new line. Respond with 1-2 sentences only. Minimal stage directions. DO NOT blow your cover! """, model = "claude-haiku-4-5-20251001", temperature = 0.8, max_tokens = 256 }) guard = claude.session({ system = """ You are a dim-witted security guard at ACME Products. You're bored and want to feel important. You ask questions and chat just to seem like you're doing your job. Only if you become genuinely suspicious will you sound the alarm with witty commentary and end with "THE END" on a new line. Respond with 1-2 sentences only. Minimal stage directions. Stay in character! """, model = "claude-haiku-4-5-20251001", temperature = 0.8, max_tokens = 256 }) function is_story_end(response) return contains(response, "THE END", true) end turn = 0 max_turns = 20 story_over = false transcript = [] guard_says = "Excuse me, sir?" print(ansi.warning("Guard: {{guard_says}}\n")) while turn < max_turns and not story_over do turn = turn + 1 // spy's turn write(ansi.error("Bob: ")) busy("...") spy_says = spy.prompt(guard_says) push(transcript, "SPY: " + spy_says) write(md.ansi(spy_says)) print() busy("pausing...") sleep(3) if is_story_end(spy_says) then story_over = true break end // guard's turn write(ansi.warning("Guard: ")) busy("...") guard_says = guard.prompt(spy_says) push(transcript, "GUARD: " + guard_says) write(md.ansi(guard_says)) print() busy("pausing...") sleep(3) if is_story_end(guard_says) then story_over = true break end end /* PART 2: Comedy Writer Rewrite Takes the raw dialogue and transforms it into a proper screenplay with character details, blocking, and comedic timing cues. */ writer = claude.session({ system = """ You are a brilliant but overworked writer. You work for a popular sketch comedy show. """, model = "claude-haiku-4-5-20251001", temperature = 0.8, max_tokens = 8000 }) prompt = """ Here's a real conversation between a spy and a ecurity guard. {{join(transcript, "\n\n")}} Re-write this as a short comedic screenplay. Keep the general story outline but make it funny. **Really funny** to a general audience. """ write(ansi.success("Writer: ")) busy("writing...") writer_response = writer.prompt(prompt) print(md.ansi(writer_response))