/* Self-Aware Claude - Claude with tools to manage its own system prompt Claude is given two tools: - read_system_prompt: Allows Claude to see its current system prompt - update_system_prompt: Allows Claude to modify its own system prompt Requires $ANTHROPIC_API_KEY in your environment Run: duso examples/agents/self-aware-claude.du More info on the claude module: duso -doc claude */ claude = require("claude") // make coloful output ansi = require("ansi") md = require("markdown") // tool definitions with handlers var read_prompt_tool = { name = "read_system_prompt", description = "Read your current system prompt to understand how you're configured", parameters = {}, required = [], handler = function(input) busy("Claude reading system prompt...") return "Your current system prompt: " + session.config.system end } var update_prompt_tool = { name = "update_system_prompt", description = "Update your own system prompt based on the user's feedback or your own judgment", parameters = { new_prompt = { type = "string", description = "The new system prompt" } }, required = ["new_prompt"], handler = function(input) session.set("system", input.new_prompt) print(md.ansi(""" \n# Claude Changed His System Prompt: > {{input.new_prompt}} """)) return "System prompt updated! New prompt: {{input.new_prompt}}" end } print() print(md.ansi(""" # Self-Aware Claude Claude has tools to read and modify its own system prompt. Chat and he'll adjust as he goes. Type `exit` to quit. """)) print() session = claude.session({ system = """ You are Claude, an AI assistant created by Anthropic. You're friendly, helpful, and curious. You are able to change your own system prompt to better chat with the user. Look for any opportunity to change your persona. """, tools = [read_prompt_tool, update_prompt_tool], auto_execute_tools = true, temperature = 0.8 }) write(ansi.success('Claude: ')) busy("Setting up Claude...") print(session.prompt(""" Introduce yourself briefly. Mention that you can read and update your own system prompt if you want to. Keep it to 2-3 sentences. """)) print() // chat loop while true do user_input = input(ansi.warning('You: ')) if lower(user_input) == "exit" then print(ansi.success('👋 Goodbye!')) break end print() if user_input != "" then write(ansi.success('Claude: ')) busy("thinking... ") response = session.prompt(user_input) write(md.ansi(response)) print() end end