diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 00:35:28 +0300 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 00:35:28 +0300 |
| commit | deb9c54f7ef75b73813c1709fbf98511eeab625a (patch) | |
| tree | 4cd1c2ff7e2ed507ca05dff236d73a23c93c7a5f /llm.py | |
| parent | 7a00701c535877a22f8a5ae0dfea260459407f05 (diff) | |
| download | agent-deb9c54f7ef75b73813c1709fbf98511eeab625a.tar.gz agent-deb9c54f7ef75b73813c1709fbf98511eeab625a.zip | |
fix: all action results to LLM, sys message only 1
Diffstat (limited to 'llm.py')
| -rwxr-xr-x | llm.py | 28 |
1 files changed, 10 insertions, 18 deletions
@@ -65,7 +65,7 @@ def path_checked(path: Path, cwd = Path.cwd()) -> Optional[Path]: return path if path.is_relative_to(cwd) else None -def inner_query_agent(actions: list, query: str, state = ()): +def query_agent(actions: list, query: str, state = ()): state = state + ({"role": "user", "content": query},) @@ -76,7 +76,8 @@ def inner_query_agent(actions: list, query: str, state = ()): # Replace all fenced JSON blocks replacements = [] - for m in re.finditer(r"```json\s*(.*?)\s*```", res, re.DOTALL): + result_jsons = [] + for m in re.finditer(r"^```json\s*(.*?)\s*^```", res, re.DOTALL | re.MULTILINE): json_str = m.group(1) try: action = json.loads(json_str) @@ -87,6 +88,7 @@ def inner_query_agent(actions: list, query: str, state = ()): result_json = f(action) if result_json is not None: replacements.append((m.start(), m.end(), action["action"])) + result_jsons.append(result_json) break replaced_res = "" @@ -97,44 +99,34 @@ def inner_query_agent(actions: list, query: str, state = ()): replaced_res += res[i:] if len(replacements) > 0: - (res, state) = inner_query_agent(actions, json.dumps(result_json), state) + (res, state) = query_agent(actions, json.dumps(result_jsons), state) return (replaced_res + "\n\n" + res, state) else: return (replaced_res, state) -def query_agent(query: str, state = ()): - +def main(): actions = [ls, read, write, tldr] - - state = state + ({"role": "system", + state = ({"role": "system", "content": f"""You are an autonomous coding agent that can help with programming tasks. You can explore repositories, read files, search for information, and make changes to code. You have access to the following actions, which you should embed in JSON markdown blocks "```json ACTION ```" in your responses. {'\n'.join(map(lambda f: '* ' + f.__doc__, actions))} +After reading the relevant files, remember to analyze the task at hand and break it into steps. + Once you are finished with your task, give a response with none of the above JSON commands. """},) - - state = state + ({"role": "system", "content": "Analyze the following user-given task and break it down into steps."},) - - return inner_query_agent(actions, query, state) - -def main(): - - state = () - while True: query = input("> ").strip() - (response, state) = query_agent(query, state) + (response, state) = query_agent(actions, query, state) print(response) if __name__ == "__main__": main() - |
