Skip to content

Commit 902665a

Browse files
committed
Chore: Add documentation for context
1 parent 1b557d1 commit 902665a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docs/docs/03-tools/05-context.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Context
2+
3+
GPTScript supports context provider tools which can be used to provide additional context for tool execution.
4+
5+
## Writing a Context Provider Tool
6+
7+
A context provider tool looks just like any other GPTScript, with the following caveats:
8+
- It cannot call the LLM and must run a command.
9+
- It must print contents to stdout.
10+
- Tools can be provided using `Export`. Any tool defined in `Tools` will be ignored.
11+
12+
Here is a simple example of a context provider tool that provides additional context to search tool:
13+
14+
```yaml
15+
# my-search-context-tool.gpt
16+
name: search_context
17+
export: sys.http.html2text?
18+
19+
#!/bin/bash
20+
echo You are an expert web researcher with access to the Search tool.If the search tool fails to return any information stop execution of the script with message "Sorry! Search did not retrun any results" . Feel free to get the contents of the returned URLs in order to get more information. Provide as much detail as you can. Also return the source of the search results.
21+
22+
```
23+
24+
## Using a Context Provider Tool
25+
26+
Continuing with the above example, this is how you can use it in a script:
27+
28+
```yaml
29+
context: search_context from my-search-context-tool.gpt
30+
tools: github.com/gptscript-ai/search/duckduckgo
31+
32+
What are some of the most popular tourist destinations in Scotland, and how many people visit them each year?
33+
34+
```
35+
36+
When you run this script, GPTScript will use the output from the context tool and add it to the user message along with the
37+
existing prompt in this tool to provide additional context to LLM.
38+
39+
## Context Provider Tool with args
40+
41+
Here is an example of a context provider tool that uses args to decide which search tool to use when answering the user provided queries:
42+
43+
```yaml
44+
# context_with_arg.gpt
45+
name: search_context
46+
export: github.com/gptscript-ai/search/duckduckgo, github.com/gptscript-ai/search/brave, sys.http.html2text?
47+
args: search_tool: tool to search with
48+
49+
#!/bin/bash
50+
echo You are an expert web researcher with access to the ${search_tool} Search tool.If the search tool fails to return any information stop execution of the script with message "Sorry! Search did not retrun any results" . Feel free to get the contents of the returned URLs in order to get more information. Provide as much detail as you can. Also return the source of the search results.
51+
52+
```
53+
54+
Continuing with the above example, this is how you can use it in a script:
55+
56+
```yaml
57+
# my_context_with_arg.gpt
58+
context: search_context from context_with_arg.gpt with ${search} as search_tool
59+
Args: search: Search tool to use
60+
61+
What are some of the most popular tourist destinations in Scotland, and how many people visit them each year?
62+
63+
```
64+
65+
This script can be used to search with `brave` or `duckduckdb` tools depending on the search parameter passed to the tool.
66+
Example usage for using brave search tool:
67+
```yaml
68+
gptscript --disable-cache my_context_with_arg.gpt '{"search": "brave"}'
69+
```

0 commit comments

Comments
 (0)