Skip to content

Commit 6076b01

Browse files
committed
Chore: Add documentation for context
1 parent a1a3b7f commit 6076b01

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

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

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Context
2+
3+
GPTScript supports context provider tools which can be used to provide additional context for tool execution. Output from the context tool gets prepended to the instruction of the current tool that uses the context tool.
4+
5+
## Writing a Context Provider Tool
6+
7+
Here is a simple example of a context provider tool that provides additional context to search tool:
8+
9+
```yaml
10+
# my-search-context-tool.gpt
11+
name: search_context
12+
export: sys.http.html2text?
13+
14+
#!/bin/bash
15+
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 return 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.
16+
17+
```
18+
19+
## Using a Context Provider Tool
20+
21+
Continuing with the above example, this is how you can use it in a script:
22+
23+
```yaml
24+
context: search_context from my-search-context-tool.gpt
25+
tools: github.com/gptscript-ai/search/duckduckgo
26+
27+
What are some of the most popular tourist destinations in Scotland, and how many people visit them each year?
28+
29+
```
30+
31+
When you run this script, GPTScript will use the output from the context tool and add it to the user message along with the
32+
existing prompt in this tool to provide additional context to LLM.
33+
34+
## Context Provider Tool with args
35+
36+
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:
37+
38+
```yaml
39+
# context_with_arg.gpt
40+
name: search_context
41+
export: github.com/gptscript-ai/search/duckduckgo, github.com/gptscript-ai/search/brave, sys.http.html2text?
42+
args: search_tool: tool to search with
43+
44+
#!/bin/bash
45+
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 return 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.
46+
47+
```
48+
49+
Continuing with the above example, this is how you can use it in a script:
50+
51+
```yaml
52+
# my_context_with_arg.gpt
53+
context: search_context from context_with_arg.gpt with ${search} as search_tool
54+
Args: search: Search tool to use
55+
56+
What are some of the most popular tourist destinations in Scotland, and how many people visit them each year?
57+
58+
```
59+
60+
This script can be used to search with `brave` or `duckduckdb` tools depending on the search parameter passed to the tool.
61+
Example usage for using brave search tool:
62+
```yaml
63+
gptscript --disable-cache my_context_with_arg.gpt '{"search": "brave"}'
64+
```

0 commit comments

Comments
 (0)