Skip to content

Commit

Permalink
proper xml schema result adding as user message, xml schema example
Browse files Browse the repository at this point in the history
  • Loading branch information
markokraemer committed Nov 18, 2024
1 parent 320dabb commit 5355771
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 554 deletions.
11 changes: 2 additions & 9 deletions agentpress/examples/example_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,22 @@
import logging
from typing import AsyncGenerator
import sys
from agentpress.xml_tool_parser import XMLToolParser
from agentpress.xml_tool_executor import XMLToolExecutor
from agentpress.xml_results_adder import XMLResultsAdder

async def run_agent(thread_id: str, max_iterations: int = 5):
# Initialize managers and tools
thread_manager = ThreadManager()
state_manager = StateManager()

# Initialize tools
thread_manager.add_tool(FilesTool)
thread_manager.add_tool(TerminalTool)

async def init():
pass

async def pre_iteration():
# Update files state
files_tool = FilesTool()
await files_tool._init_workspace_state()

async def after_iteration():
# Ask the user for a custom message or use the default
custom_message = input("Enter a message to send (or press Enter to use 'Continue!!!' as message): ")

message_content = custom_message if custom_message else """
Expand Down Expand Up @@ -151,8 +144,8 @@ async def finalizer():
max_tokens=8096,
tool_choice="auto",
temporary_message=state_message,
native_tool_calling=True,
xml_tool_calling=False,
native_tool_calling=False,
xml_tool_calling=True,
stream=True,
execute_tools_on_stream=True,
parallel_tool_execution=True
Expand Down
18 changes: 15 additions & 3 deletions agentpress/examples/example_agent/tools/files_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ async def _update_workspace_state(self):
{"param_name": "file_path", "node_type": "attribute", "path": "."},
{"param_name": "file_contents", "node_type": "content", "path": "."}
],
description="Create a new file with the provided contents"
example='''
<create-file file_path="path/to/file">
File contents go here
</create-file>
'''
)
async def create_file(self, file_path: str, file_contents: str) -> ToolResult:
try:
Expand Down Expand Up @@ -177,7 +181,10 @@ async def create_file(self, file_path: str, file_contents: str) -> ToolResult:
mappings=[
{"param_name": "file_path", "node_type": "attribute", "path": "."}
],
description="Delete a file at the given path"
example='''
<delete-file file_path="path/to/file">
</delete-file>
'''
)
async def delete_file(self, file_path: str) -> ToolResult:
try:
Expand Down Expand Up @@ -221,7 +228,12 @@ async def delete_file(self, file_path: str) -> ToolResult:
{"param_name": "old_str", "node_type": "element", "path": "old_str"},
{"param_name": "new_str", "node_type": "element", "path": "new_str"}
],
description="Replace text in a file"
example='''
<str-replace file_path="path/to/file">
<old_str>text to replace</old_str>
<new_str>replacement text</new_str>
</str-replace>
'''
)
async def str_replace(self, file_path: str, old_str: str, new_str: str) -> ToolResult:
try:
Expand Down
6 changes: 5 additions & 1 deletion agentpress/examples/example_agent/tools/terminal_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ async def _update_command_history(self, command: str, output: str, success: bool
mappings=[
{"param_name": "command", "node_type": "content", "path": "."}
],
description="Execute a shell command in the workspace directory"
example='''
<execute-command>
npm install package-name
</execute-command>
'''
)
async def execute_command(self, command: str) -> ToolResult:
original_dir = os.getcwd()
Expand Down
85 changes: 0 additions & 85 deletions agentpress/examples/example_agent/workspace/index.html

This file was deleted.

61 changes: 0 additions & 61 deletions agentpress/examples/example_agent/workspace/script.js

This file was deleted.

Loading

0 comments on commit 5355771

Please sign in to comment.