Skip to main content
View Notebook on Github

Anthropic Example for understanding Tools

Anthropic’s tool returns are not as simple as getting a few strings! While this system is more complex than those before it, it’s also simple enough to be used without problem once you understand how it works! To get started, we will import Agentops and Anthropic.

Installation

Setup

Setup our generic default statements:
And set our API keys.
Now let’s set the client as Anthropic and make an AgentOps trace.

Creating a Dummy Tool

Now to create a simple dummy tool! We are going to make a tool that will tell us about the demon infestation levels for 3 areas. From there, we will have VEGA, our AI determine the best place for the Doom Slayer to attack.
Now that that’s done, we can make a function! We will generate three random missions and pass it off to the AI.

Constructing the Message Stream

Now to the real core of this; making our message stream! We create this as a function we can call later! I create examples since the LLM’s context size can handle it (and it’s generally good practice)! We are also going to take several steps here; we must create an example of the tool being used as context. Next, we must add the generated lines to the messages list once done being generated. Finally, we will parse the text for the format we want and request another line. Now we make a message! This time around we will skip making an initial message that has too much context, unlike in the past!
Now to construct a request!
Having trouble understanding this? The first block given is always AI dialogue! You can use response.content[0].text to get the AI’s text! Let’s try it below.
The code below finds the tool used!
Now we add these as context to the LLM through initial_messages!
And now to get a response!
Isolate again!
Hmmm, what if we wanted to include more tools and add inputs? Let’s create two new functions to display this! One will show the kind of demon we are facing, whereas another one will take our weapon input to determine what the best weapon chain to use is (You heard that right, we believe in quick weapon switches around these parts)
Now we can keep the initial_messages from before actually! However let’s change the context.
And we of course make functions.
And now inventory.
With that, let’s construct our new tools and run this!!
Display just the text.
And now to get the information and put it all together! PLEASE read the comments!
And now we are basically done! We can give this to the AI and see what we get.