Tools#
Tools available in gptme.
The main tools can be grouped in the following categories:
Shell#
The assistant can execute shell commands by outputting code blocks with bash or sh as the language.
# Examples
User |
list the current directory |
Assistant |
To list the files in the current directory, use `ls`: |
System |
Ran command: `ls` |
The assistant can learn context by exploring the filesystem
User |
learn about the project |
Assistant |
Lets start by checking the files |
System |
|
Assistant |
Now lets check the README |
System |
|
Assistant |
Now we check main.py |
System |
|
Assistant |
The project is... |
Create vue project
User |
Create a new vue project with typescript and pinia named fancy-project |
Assistant |
Sure! Let's create a new vue project with TypeScript and Pinia named fancy-project: |
System |
|
- gptme.tools.shell.execute_shell(code: str, ask: bool, args: list[str]) Generator[Message, None, None]
Executes a shell command and returns the output.
Python#
The assistant can execute Python code blocks.
It uses IPython to do so, and persists the IPython instance between calls to give a REPL-like experience.
# Examples
Results of the last expression will be displayed, IPython-style:
User |
What is 2 + 2? |
Assistant |
|
System |
Executed code block. |
It can write an example and then execute it:
User |
compute fib 10 |
Assistant |
To compute the 10th Fibonacci number, we write a recursive function: |
System |
Executed code block. |
- gptme.tools.python.execute_python(code: str, ask: bool, args=None) Generator[Message, None, None]
Executes a python codeblock and returns the output.
- gptme.tools.python.get_installed_python_libraries() set[str]
Check if a select list of Python libraries are installed.
- gptme.tools.python.register_function(func: T) T
Decorator to register a function to be available in the IPython instance.
Tmux#
You can use the tmux tool to run long-lived and/or interactive applications in a tmux session. Requires tmux to be installed.
This tool is suitable to run long-running commands or interactive applications that require user input.
Examples of such commands: npm run dev
, python3 server.py
, python3 train.py
, etc.
It allows for inspecting pane contents and sending input.
# Examples
Managing a dev server
User |
Start the dev server |
Assistant |
Certainly! To start the dev server we should use tmux: |
System |
Running `npm run dev` in session 0 |
User |
Can you show me the current content of the pane? |
Assistant |
Of course! Let's inspect the pane content: |
System |
|
User |
Stop the dev server |
Assistant |
I'll send 'Ctrl+C' to the pane to stop the server: |
System |
Sent 'C-c' to pane 0 |
Get info from ncurses applications
User |
start top and give me a summary |
System |
Running `top` in session 1. |
Assistant |
The load is... |
- gptme.tools.tmux.execute_tmux(code: str, ask: bool, args: list[str]) Generator[Message, None, None]
Executes a command in tmux and returns the output.
Save#
Gives the assistant the ability to save/write code to a file.
# Examples
User |
write a hello world script to hello.py |
System |
Saved to `hello.py` |
User |
make it all-caps |
System |
Saved to `hello.py` |
# Examples
User |
append a print "Hello world" to hello.py |
Assistant |
|
System |
Appended to `hello.py` |
- gptme.tools.save.execute_append(code: str, ask: bool, args: list[str]) Generator[Message, None, None]
Append code to a file.
- gptme.tools.save.execute_save(code: str, ask: bool, args: list[str]) Generator[Message, None, None]
Save code to a file.
Patch#
Gives the LLM agent the ability to patch text files, by using a adapted version git conflict markers.
# Examples
User |
patch the file `hello.py` to ask for the name of the user |
Assistant |
```patch hello.py <<<<<<< ORIGINAL def hello(): print("Hello world") ======= def hello(): name = input("What is your name? ") print(f"Hello {name}") >>>>>>> UPDATED ``` |
System |
Patch applied |
- class gptme.tools.patch.Patch
Patch(original: str, updated: str)
- __init__(original: str, updated: str) None
- diff_minimal(strip_context=False) str
Show a minimal diff of the patch. Note that a minimal diff isn’t necessarily a unique diff.
- gptme.tools.patch.apply(codeblock: str, content: str) str
Applies multiple patches in
codeblock
tocontent
.
- gptme.tools.patch.execute_patch(code: str, ask: bool, args: list[str]) Generator[Message, None, None]
Applies the patch.
Browser#
- Tools to let the assistant control a browser, including:
loading pages
reading their contents
viewing them through screenshots
searching
Note
This is an experimental feature. It needs some work to be more robust and useful.
# Examples
Answer question from URL with browsing
User |
find out which is the latest ActivityWatch version from superuserlabs.org |
Assistant |
Let's browse the site. |
System |
|
Assistant |
Couldn't find the answer on the page. Following link to the ActivityWatch website. |
System |
|
Assistant |
The latest version of ActivityWatch is v0.12.2 |
Searching
User |
who is the founder of ActivityWatch? |
Assistant |
Let's search for that. |
System |
|
Assistant |
Following link to the ActivityWatch website. |
System |
|
Assistant |
The founder of ActivityWatch is Erik Bjäreholt. |
Take screenshot of page
User |
take a screenshot of the ActivityWatch website |
Assistant |
Certainly! I'll use the browser tool to screenshot the ActivityWatch website. |
System |
|
- gptme.tools.browser.read_url(url: str) str
Read the text of a webpage and return the text in Markdown format.
- gptme.tools.browser.screenshot_url(url: str, filename: str | None = None) str
Take a screenshot of a webpage and save it to a file.
- gptme.tools.browser.search(query: str, engine: Literal['google', 'duckduckgo'] = 'google') str
Search for a query on a search engine.
Chats#
List, search, and summarize past conversation logs.
# Examples
Search for a specific topic in past conversations
User |
Can you find any mentions of "python" in our past conversations? |
Assistant |
Certainly! I'll search our past conversations for mentions of "python" using the search_chats function. |
- gptme.tools.chats.list_chats(max_results: int = 5, include_summary: bool = False) None
List recent chat conversations and optionally summarize them using an LLM.
- Parameters:
max_results (int) – Maximum number of conversations to display.
include_summary (bool) – Whether to include a summary of each conversation. If True, uses an LLM to generate a comprehensive summary. If False, uses a simple strategy showing snippets of the first and last messages.
- gptme.tools.chats.read_chat(conversation: str, max_results: int = 5, incl_system=False) None
Read a specific conversation log.
- Parameters:
conversation (str) – The name of the conversation to read.
max_results (int) – Maximum number of messages to display.
incl_system (bool) – Whether to include system messages.
- gptme.tools.chats.search_chats(query: str, max_results: int = 5, system=False) None
Search past conversation logs for the given query and print a summary of the results.
- Parameters:
query (str) – The search query.
max_results (int) – Maximum number of conversations to display.
system (bool) – Whether to include system messages in the search.