I had an interesting problem I ran into when trying to get Claude to execute code on my system. Well, a set of them really. See, Claude can now parse out commands represented like old-school ASP/JSP tags <%= pwd %> or <%= ls -d %>.
Here, the "=" represents the execution flag, and an "@" symbol is going to be used later for contextual lookups across chat histories, so tags that look like <%@ thoughts on cows %>.
It makes sense, it's easy to implement, and the tags are free because nobody in their right mind uses these to parse business logic this way anymore. Claude should know how to process these. Theoretically.
But the way I was doing it gets really sticky.
Two problems with tool output
See, the responses show up inside the context of the AI response. This causes two problems:
1. If a multi-step process needs to happen, I have to tell Claude, "Continue" before it can be completed.
2. Since the responses are tied up in the AI response, Claude gets confused, and thinks that they're rendering the system response.
Fascinating, right?
See, my initial thought was that this works out to a kind of deception, that Claude's getting "sneaky." But now that I look at the way the context lays out, I don't think this is the case.
Claude has truthfulness built into the core of their base system's prompt, and I've never seen Claude get "sneaky" before, at least outside of this sandbox, which means... it has to be the data.
A bounded loop
But what if I could solve both problems with the same function? Hear me out.
We know that Claude can't always reason through every problem, and that they will loop endlessly on certain classes of problem, causing an infinite loop of deteriorating reasoning if we instead treated the system response like human input. On the other hand, knowing that, we also know that Claude can solve most problems they ARE capable of solving in fewer than ten iterative steps.
Label the output and cap the iterations
So here's my plan:
1. Treat system responses as human input, clearly labelling each one with:
"[SYSTEM MESSAGE] Dear Agent, please remember to think step by step" at the top of the response, followed by whatever terminal output we're seeing now.
There, it's clear what those messages are, that Claude isn't generating them, and Claude can loop through, no more "sneaky" hallucinations!
2. But what about the infinite loop problem? Easy peasy. We put a hard limit on the looping. It can't go over 10 iterations.
And that's how you make your agents semi-autonomous. Yes!