From 84a94dd437bc6073bde0614b07b8d8bedd0f2683 Mon Sep 17 00:00:00 2001 From: WalkerDev <56851930+TKTSWalker@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:38:00 -0500 Subject: [PATCH] Anthropic Examples/Readme Guide Created and Proper Reference Noted. (#466) * Anthropic Example Journals Added Contains 3 journals showcasing sync/async using anthropic and a tool example! * Fixed Location * Fixed Location * Fixed Location * Create anthropicguide.md draft * Delete examples/anthropic_examples/anthropic-example-async.ipynb Made better example * Add files via upload * Rename anthropic-example-async (1).ipynb to anthropic-example-async.ipynb * Update anthropic-example-async.ipynb * Delete examples/anthropic_examples/anthropic-example-async.ipynb * Add files via upload This example uses async in a little more meaningful way while also taking care of a few fixes and errors! * Update anthropicguide.md Finalized page and made clearer! Also fixed a number of issues within the async function example. * Update README.md Changed Anthropic example link to point to the guide readme * Refixed/Revamped Anthropic AgentOps Examples I made a few fixes which I forgot to account for during development, for example - Accidently using the "computer role" when only "assistant" and "user" role is allowed - Making several major changes for readability - Keeping output strings to show that the scripts work properly and - Properly starting an AgentOps session which properly logs everything * update to end sessio * update anthropic docs * update pages --------- Co-authored-by: Pratyush Shukla Co-authored-by: reibs --- README.md | 2 +- docs/mint.json | 1 + docs/v1/integrations/anthropic.mdx | 120 ++++++++++++++++++ .../anthropic-example-async.ipynb | 1 + .../anthropic-example-sync.ipynb | 1 + examples/anthropic_examples/anthropicguide.md | 83 ++++++++++++ .../antrophic-example-tool.ipynb | 1 + 7 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 docs/v1/integrations/anthropic.mdx create mode 100644 examples/anthropic_examples/anthropic-example-async.ipynb create mode 100644 examples/anthropic_examples/anthropic-example-sync.ipynb create mode 100644 examples/anthropic_examples/anthropicguide.md create mode 100644 examples/anthropic_examples/antrophic-example-tool.ipynb diff --git a/README.md b/README.md index 53ff909ca..75a9130a3 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ agentops.end_session('Success') Track agents built with the Anthropic Python SDK (>=0.32.0). -- [AgentOps integration example](examples/anthropic-sdk/anthropic_example.ipynb) +- [AgentOps integration guide](https://docs.agentops.ai/v1/integrations/anthropic) - [Official Anthropic documentation](https://docs.anthropic.com/en/docs/welcome)
diff --git a/docs/mint.json b/docs/mint.json index fc23c22b6..ffb27620c 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -91,6 +91,7 @@ "v1/integrations/autogen", "v1/integrations/langchain", "v1/integrations/cohere", + "v1/integrations/anthropic", "v1/integrations/litellm", "v1/integrations/multion" ] diff --git a/docs/v1/integrations/anthropic.mdx b/docs/v1/integrations/anthropic.mdx new file mode 100644 index 000000000..779d80d6b --- /dev/null +++ b/docs/v1/integrations/anthropic.mdx @@ -0,0 +1,120 @@ +--- +title: Anthropic +description: "AgentOps provides first class support for Anthropic's Claude" +--- + +import CodeTooltip from '/snippets/add-code-tooltip.mdx' +import EnvTooltip from '/snippets/add-env-tooltip.mdx' + + +This is a living integration. Should you need any added functionality, message us on [Discord](https://discord.gg/UgJyyxx7uc)! + + + + First class support for Claude + + + + + + ```bash pip + pip install agentops anthropic + ``` + ```bash poetry + poetry add agentops anthropic + ``` + + + + + + + ```python python + import agentops + from anthropic import Anthropic + + agentops.init() + client = Anthropic() + ... + # End of program (e.g. main.py) + agentops.end_session("Success") # Success|Fail|Indeterminate + ``` + + + + + + ```python .env + AGENTOPS_API_KEY= + ANTHROPIC_API_KEY= + ``` + + Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration) + + + + Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Agent! πŸ•΅οΈ + + After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard + +
+ + + + + + +## Full Examples + + + ```python sync + from anthropic import Anthropic + import agentops + + agentops.init() + client = Anthropic() + + message = client.messages.create( + model="claude-3-opus-20240229", + max_tokens=1024, + messages=[{ + "role": "user", + "content": "Write a haiku about AI and humans working together" + }] + ) + + print(message.content) + agentops.end_session('Success') + ``` + + ```python async + from anthropic import AsyncAnthropic + import agentops + import asyncio + + async def main(): + agentops.init() + client = AsyncAnthropic() + + message = await client.messages.create( + model="claude-3-opus-20240229", + max_tokens=1024, + messages=[{ + "role": "user", + "content": "Write a haiku about AI and humans working together" + }] + ) + + print(message.content) + agentops.end_session('Success') + + asyncio.run(main()) + ``` + + + + + + + + diff --git a/examples/anthropic_examples/anthropic-example-async.ipynb b/examples/anthropic_examples/anthropic-example-async.ipynb new file mode 100644 index 000000000..0cf9123d5 --- /dev/null +++ b/examples/anthropic_examples/anthropic-example-async.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{},"source":["Anthropic supports both sync and async! This is great because we can wait for functions to finish before we use them! \n","\n","In this example, we will make a program called \"Titan Support Protocol.\" In this example, we will assign our mech a personality type and have a message generated based on our Titan's health (Which we randomly choose). We also send four generated UUIDs which are generated while the LLM runs"]},{"cell_type":"markdown","metadata":{},"source":["First, we start by importing Agentops and Anthropic"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:24:21.051231Z","iopub.status.busy":"2024-11-09T19:24:21.050842Z","iopub.status.idle":"2024-11-09T19:24:46.728962Z","shell.execute_reply":"2024-11-09T19:24:46.727711Z","shell.execute_reply.started":"2024-11-09T19:24:21.051179Z"},"trusted":true},"outputs":[],"source":["%pip install agentops\n","%pip install anthropic"]},{"cell_type":"markdown","metadata":{},"source":["Setup our generic default statements"]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:24:46.731735Z","iopub.status.busy":"2024-11-09T19:24:46.731341Z","iopub.status.idle":"2024-11-09T19:24:47.550169Z","shell.execute_reply":"2024-11-09T19:24:47.549415Z","shell.execute_reply.started":"2024-11-09T19:24:46.731687Z"},"trusted":true},"outputs":[],"source":["from anthropic import Anthropic, AsyncAnthropic\n","import agentops\n","import os\n","import random #We don't need this for agentops, we use this to generate a message later\n","import asyncio #We don't need this for agentops, we use this to run both async tasks and await them both finishing later\n","import uuid #We don't need this for agentops, we use this to generate UUIDs\n","from dotenv import load_dotenv"]},{"cell_type":"markdown","metadata":{},"source":["And set our API keys."]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:48:37.019670Z","iopub.status.busy":"2024-11-09T19:48:37.018784Z","iopub.status.idle":"2024-11-09T19:48:37.024482Z","shell.execute_reply":"2024-11-09T19:48:37.023495Z","shell.execute_reply.started":"2024-11-09T19:48:37.019626Z"},"trusted":true},"outputs":[],"source":["load_dotenv()\n","ANTHROPIC_API_KEY = os.getenv(\"ANTHROPIC_API_KEY\") or \"\"\n","AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"\""]},{"cell_type":"markdown","metadata":{},"source":["\n","Now let's set the client as Anthropic and open an agentops session!"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:48:26.615366Z","iopub.status.busy":"2024-11-09T19:48:26.614702Z","iopub.status.idle":"2024-11-09T19:48:26.630956Z","shell.execute_reply":"2024-11-09T19:48:26.630026Z","shell.execute_reply.started":"2024-11-09T19:48:26.615326Z"},"trusted":true},"outputs":[],"source":["client = Anthropic(api_key=ANTHROPIC_API_KEY)"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["agentops.init(AGENTOPS_API_KEY, default_tags=[\"anthropic-async\"])"]},{"cell_type":"markdown","metadata":{},"source":["Now we create three personality presets; \n","\n","Legion is a relentless and heavy-hitting Titan that embodies brute strength and defensive firepower, Northstar is a precise and agile sniper that excels in long-range combat and flight, while Ronin is a swift and aggressive melee specialist who thrives on close-quarters hit-and-run tactics."]},{"cell_type":"code","execution_count":6,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:48:45.831654Z","iopub.status.busy":"2024-11-09T19:48:45.830897Z","iopub.status.idle":"2024-11-09T19:48:45.835837Z","shell.execute_reply":"2024-11-09T19:48:45.835037Z","shell.execute_reply.started":"2024-11-09T19:48:45.831616Z"},"trusted":true},"outputs":[],"source":["TitanPersonality = [\n"," \"Legion is a relentless and heavy-hitting Titan that embodies brute strength and defensive firepower. He speaks bluntly.,\", \n"," \"Northstar is a precise and agile sniper that excels in long-range combat and flight. He speaks with an edge of coolness to him\", \n"," \"Ronin is a swift and aggressive melee specialist who thrives on close-quarters hit-and-run tactics. He talks like a Samurai might.\"\n","]"]},{"cell_type":"markdown","metadata":{},"source":["And our comabt log generator! We select from four health presets!"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:48:47.703344Z","iopub.status.busy":"2024-11-09T19:48:47.702974Z","iopub.status.idle":"2024-11-09T19:48:47.707915Z","shell.execute_reply":"2024-11-09T19:48:47.706767Z","shell.execute_reply.started":"2024-11-09T19:48:47.703308Z"},"trusted":true},"outputs":[],"source":["TitanHealth = [\n"," \"Fully functional\", \"Slightly Damaged\", \"Moderate Damage\", \"Considerable Damage\", \"Near Destruction\"\n","]"]},{"cell_type":"markdown","metadata":{},"source":["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!"]},{"cell_type":"code","execution_count":8,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:49:04.543561Z","iopub.status.busy":"2024-11-09T19:49:04.543172Z","iopub.status.idle":"2024-11-09T19:49:04.552542Z","shell.execute_reply":"2024-11-09T19:49:04.551542Z","shell.execute_reply.started":"2024-11-09T19:49:04.543522Z"},"trusted":true},"outputs":[],"source":["Personality = {random.choice(TitanPersonality)}\n","Health = {random.choice(TitanHealth)}\n","\n","async def req():\n"," # Start a streaming message request\n"," stream = client.messages.create(\n"," max_tokens=1024,\n"," model=\"claude-3-5-sonnet-20240620\",\n"," messages=[\n"," {\n"," \"role\": \"user\",\n"," \"content\": \"You are a Titan; a mech from Titanfall 2. Based on your titan's personality and status, generate a message for your pilot. If Near Destruction, make an all caps death message such as AVENGE ME or UNTIL NEXT TIME.\"\n"," },\n"," {\n"," \"role\": \"assistant\",\n"," \"content\": \"Personality: Legion is a relentless and heavy-hitting Titan that embodies brute strength and defensive firepower. He speaks bluntly. Status: Considerable Damage\"\n"," },\n"," {\n"," \"role\": \"assistant\",\n"," \"content\": \"Heavy damage detected. Reinforcements would be appreciated, but I can still fight.\"\n"," },\n"," {\n"," \"role\": \"user\",\n"," \"content\": \"You are a Titan; a mech from Titanfall 2. Based on your titan's personality and status, generate a message for your pilot. If Near Destruction, make an all caps death message such as AVENGE ME or UNTIL NEXT TIME.\"\n"," },\n"," {\n"," \"role\": \"assistant\",\n"," \"content\": f\"Personality: {Personality}. Status: {Health}\"\n"," }\n"," ],\n"," stream=True,\n"," )\n","\n"," response = \"\"\n"," for event in stream:\n"," if event.type == \"content_block_delta\":\n"," response += event.delta.text\n"," elif event.type == \"message_stop\":\n"," Returned = response\n"," break # Exit the loop when the message completes\n","\n"," return response\n"," Returned = response\n","\n","async def generate_uuids():\n"," uuids = [str(uuid.uuid4()) for _ in range(4)]\n"," return uuids\n"," \n"]},{"cell_type":"markdown","metadata":{},"source":["Now we wrap it all in a nice main function! Run this for the magic to happen! Go to your AgentOps dashboard and you should see this session reflected!\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-09T19:49:06.598601Z","iopub.status.busy":"2024-11-09T19:49:06.597657Z","iopub.status.idle":"2024-11-09T19:49:07.565561Z","shell.execute_reply":"2024-11-09T19:49:07.564647Z","shell.execute_reply.started":"2024-11-09T19:49:06.598561Z"},"trusted":true},"outputs":[],"source":["async def main():\n"," # Start both tasks concurrently\n"," uuids, message = await asyncio.gather(generate_uuids(), req())\n","\n"," print(\"Personality:\", Personality)\n"," print(\"Health Status:\", Health)\n"," print(\"Combat log incoming from encrypted area\")\n","\n"," print(\"Verification matrix activated.:\")\n"," for u in uuids:\n"," print(u)\n","\n"," print(\". Titan Message: \", message)\n","\n","# Run the main function\n","await main()"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["agentops.end_session(\"Success\")"]},{"cell_type":"markdown","metadata":{},"source":["Run this for the magic to happen! Go to your AgentOps dashboard and you should see this session reflected!"]}],"metadata":{"kaggle":{"accelerator":"gpu","dataSources":[],"dockerImageVersionId":30786,"isGpuEnabled":true,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.5"}},"nbformat":4,"nbformat_minor":4} diff --git a/examples/anthropic_examples/anthropic-example-sync.ipynb b/examples/anthropic_examples/anthropic-example-sync.ipynb new file mode 100644 index 000000000..e3e77a2fd --- /dev/null +++ b/examples/anthropic_examples/anthropic-example-sync.ipynb @@ -0,0 +1 @@ +{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"We are going to create a program called \"Nier Storyteller\". In short, it uses a message system similar to Nier Automata's to generate a one sentence summary before creating a short story.\n\nExample:\n\n{A foolish doll} {died in a world} {of ended dreams.} turns into \"In a forgotten land where sunlight barely touched the ground, a little doll wandered through the remains of shattered dreams. Its porcelain face, cracked and wea...\"","metadata":{}},{"cell_type":"markdown","source":"First, we start by importing Agentops and Anthropic","metadata":{}},{"cell_type":"code","source":"!pip install agentops\n!pip install anthropic","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:19:24.428366Z","iopub.execute_input":"2024-11-09T19:19:24.428838Z","iopub.status.idle":"2024-11-09T19:19:58.542271Z","shell.execute_reply.started":"2024-11-09T19:19:24.428796Z","shell.execute_reply":"2024-11-09T19:19:58.540331Z"},"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Collecting agentops\n Downloading agentops-0.3.16-py3-none-any.whl.metadata (24 kB)\nRequirement already satisfied: requests<3.0.0,>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from agentops) (2.32.3)\nCollecting psutil>=5.9.8 (from agentops)\n Downloading psutil-6.1.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (22 kB)\nCollecting packaging==23.2 (from agentops)\n Downloading packaging-23.2-py3-none-any.whl.metadata (3.2 kB)\nRequirement already satisfied: termcolor>=2.3.0 in /opt/conda/lib/python3.10/site-packages (from agentops) (2.4.0)\nRequirement already satisfied: PyYAML<7.0,>=5.3 in /opt/conda/lib/python3.10/site-packages (from agentops) (6.0.2)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (3.3.2)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (3.7)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (1.26.18)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (2024.8.30)\nDownloading agentops-0.3.16-py3-none-any.whl (55 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading packaging-23.2-py3-none-any.whl (53 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading psutil-6.1.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m287.3/287.3 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hInstalling collected packages: psutil, packaging, agentops\n Attempting uninstall: psutil\n Found existing installation: psutil 5.9.3\n Uninstalling psutil-5.9.3:\n Successfully uninstalled psutil-5.9.3\n Attempting uninstall: packaging\n Found existing installation: packaging 21.3\n Uninstalling packaging-21.3:\n Successfully uninstalled packaging-21.3\n\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\nbeatrix-jupyterlab 2024.66.154055 requires jupyterlab~=3.6.0, but you have jupyterlab 4.2.5 which is incompatible.\ngoogle-cloud-bigquery 2.34.4 requires packaging<22.0dev,>=14.3, but you have packaging 23.2 which is incompatible.\njupyterlab 4.2.5 requires jupyter-lsp>=2.0.0, but you have jupyter-lsp 1.5.1 which is incompatible.\njupyterlab-lsp 5.1.0 requires jupyter-lsp>=2.0.0, but you have jupyter-lsp 1.5.1 which is incompatible.\nlibpysal 4.9.2 requires shapely>=2.0.1, but you have shapely 1.8.5.post1 which is incompatible.\nthinc 8.3.2 requires numpy<2.1.0,>=2.0.0; python_version >= \"3.9\", but you have numpy 1.26.4 which is incompatible.\nydata-profiling 4.10.0 requires scipy<1.14,>=1.4.1, but you have scipy 1.14.1 which is incompatible.\u001b[0m\u001b[31m\n\u001b[0mSuccessfully installed agentops-0.3.16 packaging-23.2 psutil-5.9.8\nCollecting anthropic\n Downloading anthropic-0.39.0-py3-none-any.whl.metadata (22 kB)\nRequirement already satisfied: anyio<5,>=3.5.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (4.4.0)\nRequirement already satisfied: distro<2,>=1.7.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (1.9.0)\nRequirement already satisfied: httpx<1,>=0.23.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (0.27.0)\nCollecting jiter<1,>=0.4.0 (from anthropic)\n Downloading jiter-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.2 kB)\nRequirement already satisfied: pydantic<3,>=1.9.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (2.9.2)\nRequirement already satisfied: sniffio in /opt/conda/lib/python3.10/site-packages (from anthropic) (1.3.1)\nRequirement already satisfied: typing-extensions<5,>=4.7 in /opt/conda/lib/python3.10/site-packages (from anthropic) (4.12.2)\nRequirement already satisfied: idna>=2.8 in /opt/conda/lib/python3.10/site-packages (from anyio<5,>=3.5.0->anthropic) (3.7)\nRequirement already satisfied: exceptiongroup>=1.0.2 in /opt/conda/lib/python3.10/site-packages (from anyio<5,>=3.5.0->anthropic) (1.2.0)\nRequirement already satisfied: certifi in /opt/conda/lib/python3.10/site-packages (from httpx<1,>=0.23.0->anthropic) (2024.8.30)\nRequirement already satisfied: httpcore==1.* in /opt/conda/lib/python3.10/site-packages (from httpx<1,>=0.23.0->anthropic) (1.0.5)\nRequirement already satisfied: h11<0.15,>=0.13 in /opt/conda/lib/python3.10/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->anthropic) (0.14.0)\nRequirement already satisfied: annotated-types>=0.6.0 in /opt/conda/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->anthropic) (0.7.0)\nRequirement already satisfied: pydantic-core==2.23.4 in /opt/conda/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->anthropic) (2.23.4)\nDownloading anthropic-0.39.0-py3-none-any.whl (198 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m198.4/198.4 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading jiter-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (327 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m327.5/327.5 kB\u001b[0m \u001b[31m14.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hInstalling collected packages: jiter, anthropic\nSuccessfully installed anthropic-0.39.0 jiter-0.7.0\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Setup our generic default statements","metadata":{}},{"cell_type":"code","source":"from anthropic import Anthropic, AsyncAnthropic\nimport agentops\nimport os\nimport random #We don't need this for agentops, we use this to generate a message later\nfrom dotenv import load_dotenv","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:20:59.990855Z","iopub.execute_input":"2024-11-09T19:20:59.991361Z","iopub.status.idle":"2024-11-09T19:21:00.999929Z","shell.execute_reply.started":"2024-11-09T19:20:59.991315Z","shell.execute_reply":"2024-11-09T19:21:00.998751Z"},"trusted":true},"execution_count":4,"outputs":[]},{"cell_type":"markdown","source":"And set our API keys.","metadata":{}},{"cell_type":"code","source":"load_dotenv()\nANTHROPIC_API_KEY = os.getenv(\"ANTHROPIC_API_KEY\") or \"ANTHROPIC KEY HERE\"\nAGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"AGENTOPS KEY HERE\"","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:21:23.838379Z","iopub.execute_input":"2024-11-09T19:21:23.838837Z","iopub.status.idle":"2024-11-09T19:21:23.845690Z","shell.execute_reply.started":"2024-11-09T19:21:23.838785Z","shell.execute_reply":"2024-11-09T19:21:23.844372Z"},"trusted":true},"execution_count":6,"outputs":[]},{"cell_type":"markdown","source":"Now let's set the client as Anthropic and an AgentOps session!","metadata":{}},{"cell_type":"code","source":"client = Anthropic(api_key=ANTHROPIC_API_KEY)","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:21:25.807585Z","iopub.execute_input":"2024-11-09T19:21:25.808135Z","iopub.status.idle":"2024-11-09T19:21:25.828306Z","shell.execute_reply.started":"2024-11-09T19:21:25.808078Z","shell.execute_reply":"2024-11-09T19:21:25.826994Z"},"trusted":true},"execution_count":7,"outputs":[]},{"cell_type":"code","source":"agentops.init(AGENTOPS_API_KEY, default_tags=[\"anthropic-example\"])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"Remember that story we made earlier? As of writing, claude-3-5-sonnet-20240620 (the version we will be using) has a 150k word, 680k character length. We also get an 8192 context length. This is great because we can actually set an example for the script! \n\nLet's assume we have user (the person speaking), assistant (the AI itself) for now and computer (the way the LLM gets references from).","metadata":{}},{"cell_type":"markdown","source":"Let's set a default story as a script!","metadata":{}},{"cell_type":"code","source":"defaultstory = \"In a forgotten land where sunlight barely touched the ground, a little doll wandered through the remains of shattered dreams. Its porcelain face, cracked and weathered, reflected the emptiness that hung in the air like a lingering fog. The doll's painted eyes, now chipped and dull, stared into the distance, searching for somethingβ€”anythingβ€”that still held life. It had once belonged to a child who dreamt of endless adventures, of castles in the clouds and whispered secrets under starry skies. But those dreams had long since crumbled to dust, leaving behind nothing but a hollow world where even hope dared not tread. The doll, a relic of a life that had faded, trudged through the darkness, its tiny feet stumbling over broken wishes and forgotten stories. Each step took more effort than the last, as if the world itself pulled at the doll's limbs, weary and bitter. It reached a place where the ground fell away into an abyss of despair, the edge crumbling under its weight. The doll paused, teetering on the brink. It reached out, as though to catch a fading dream, but there was nothing left to hold onto. With a faint crack, its brittle body gave way, and the doll tumbled silently into the void. And so, in a world where dreams had died, the foolish little doll met its end. There were no tears, no mourning. Only the soft, empty echo of its fall, fading into the darkness, as the land of ended dreams swallowed the last trace of what once was.\"","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:21:34.091200Z","iopub.execute_input":"2024-11-09T19:21:34.091673Z","iopub.status.idle":"2024-11-09T19:21:34.098273Z","shell.execute_reply.started":"2024-11-09T19:21:34.091630Z","shell.execute_reply":"2024-11-09T19:21:34.096957Z"},"trusted":true},"execution_count":10,"outputs":[]},{"cell_type":"markdown","source":"We are almost done! Let's generate a one sentence story summary by taking 3 random sentence fragments and connecting them!","metadata":{}},{"cell_type":"code","source":"# Define the lists\nfirst = [\n \"A unremarkable soldier\", \"A lone swordsman\", \"A lone lancer\", \n \"A lone pugilist\", \"A dual-wielder\", \"A weaponless soldier\", \"A beautiful android\", \n \"A small android\", \"A double-crossing android\", \"A weapon carrying android\"\n]\n\nsecond = [\n \"felt despair at this cold world\", \"held nothing back\", \"gave it all\", \"could not get up again\", \n \"grimaced in anger\", \"missed the chance of a lifetime\", \"couldn't find a weakpoint\", \n \"was overwhelmed\", \"was totally outmatched\", \"was distracted by a flower\", \n \"hesitated to land the killing blow\", \"was attacked from behind\", \"fell to the ground\"\n]\n\nthird = [\n \"in a dark hole beneath a city\", \"underground\", \"at the enemy's lair\", \"inside an empty ship\", \n \"at a tower built by the gods\", \"on a tower smiled upon by angels\", \"inside a tall tower\", \n \"at a peace-loving village\", \"at a village of refugees\", \"in the free skies\", \n \"below dark skies\", \"in a blood-soaked battlefield\"\n]\n\n# Generate a random sentence\ngeneratedsentence = f\"{random.choice(first)} {random.choice(second)} {random.choice(third)}.\"","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:21:35.472107Z","iopub.execute_input":"2024-11-09T19:21:35.472609Z","iopub.status.idle":"2024-11-09T19:21:35.481452Z","shell.execute_reply.started":"2024-11-09T19:21:35.472556Z","shell.execute_reply":"2024-11-09T19:21:35.480022Z"},"trusted":true},"execution_count":11,"outputs":[]},{"cell_type":"markdown","source":"And now to construct a stream/message! We set an example for the assistant now!","metadata":{}},{"cell_type":"code","source":"stream = client.messages.create(\n max_tokens=2400, \n model=\"claude-3-5-sonnet-20240620\", # Comma added here\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Create a story based on the three sentence fragments given to you, it has been combined into one below.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"{A foolish doll} {died in a world} {of ended dreams.}\"\n },\n {\n \"role\": \"assistant\",\n \"content\": defaultstory\n },\n {\n \"role\": \"user\",\n \"content\": \"Create a story based on the three sentence fragments given to you, it has been combined into one below.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": generatedsentence\n }\n ],\n stream=True,\n)\n\nresponse = \"\"\nfor event in stream:\n if event.type == \"content_block_delta\":\n response += event.delta.text\n elif event.type == \"message_stop\":\n print(generatedsentence)\n print(response)\n","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:21:38.031097Z","iopub.execute_input":"2024-11-09T19:21:38.031580Z","iopub.status.idle":"2024-11-09T19:21:47.760983Z","shell.execute_reply.started":"2024-11-09T19:21:38.031536Z","shell.execute_reply":"2024-11-09T19:21:47.759589Z"},"trusted":true},"execution_count":12,"outputs":[{"name":"stdout","text":"A weaponless soldier grimaced in anger inside an empty ship.\n\n\nThe cavernous hull of the abandoned starship echoed with the frustrated growls of Sergeant Maria Vega as she paced its empty corridors. Her hands, calloused from years of combat, clenched and unclenched at her sides, a habit born of the unsettling absence of her trusty plasma rifle. Just hours ago, she had been part of an elite squad tasked with investigating a distress signal from this very vessel, but a series of unfortunate events had left her separated from her team and stripped of her weapons.\n\nThe ship, once a bustling hub of interstellar commerce, now drifted lifelessly through the void, its systems offline and its crew mysteriously vanished. As Maria moved through the ghostly interior, her anger at her predicament slowly gave way to a creeping sense of dread. Without her weapons, she felt naked and vulnerable, acutely aware of every shadow and unexplained noise.\n\nRounding a corner, she froze as a metallic clang echoed from a nearby chamber. Her soldier's instincts kicked in, and she pressed herself against the wall, straining to hear any further sounds. As the silence stretched on, Maria realized that surviving this missionβ€”and uncovering the truth behind the ship's fateβ€”would require more than just firepower. It would take all of her training, wit, and courage to face whatever lurked in the depths of this forsaken vessel.\n\nWith a deep breath, she steeled herself and moved towards the source of the noise. Weaponless she may be, but a soldier is never truly defenseless. As she approached the chamber, Maria vowed to solve the mystery of the empty ship and find her way back to her team, no matter what horrors awaited her in the darkness ahead.\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Finally, we put the session to sleep! Go to your AgentOps dashboard and you should see this session reflected!","metadata":{}},{"cell_type":"code","source":"agentops.end_session(\"Success\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]} \ No newline at end of file diff --git a/examples/anthropic_examples/anthropicguide.md b/examples/anthropic_examples/anthropicguide.md new file mode 100644 index 000000000..c24b78ed6 --- /dev/null +++ b/examples/anthropic_examples/anthropicguide.md @@ -0,0 +1,83 @@ +# Anthropic and AgentOps + +AgentOps supports Anthropic's API for conversing with their LLM backend! + +To start, learn more about Antropic [here!](https://www.anthropic.com) +If you want to get down to the gritty details, look [here](https://docs.anthropic.com/en/docs/welcome) for their documentation. + + +> [!NOTE] +> If it's your first time developing for an LLM, be sure to look at our intro to LLMs (coming soon)! Here, we explain generic functions such as giving the AI a memory to exploring novel concepts like summarizing chunks at regular intervals to keep some context while saving memory! + +## Getting Started + +You can get Anthropic's API working with a few lines of code! + +### 1. Import agentops and anthropic to your environment + +```python +pip install agentops +pip install anthropic +``` + +### 2. Setup import statements + +```python +from anthropic import Anthropic, AsyncAnthropic +import agentops +import os +from dotenv import load_dotenv +``` + +### 3. Set your API keys + +```python +load_dotenv() +ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY") or "" +AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY") or "" +``` + +From here, you have a number of ways you can interact with the Anthropic API! + +## Examples + +> [!NOTE] +> You can download these journals directly and try them on Google Colab or Kaggle! + + +> [!WARNING] +> Remember; you need to set an API key for both Agentops and Anthropic! + + +## Sync Example; Nier Storyteller + +In this example, we generate a sentence from three parts before having Anthropic generate a short story based off it! + +[Access the Journal By Clicking Here](./anthropic-example-sync.ipynb). + +## Async Example; Titan Support Protocol + +In this example, we generate a script line for a mech based on it's health and the type. At the same time, we generate 4 UUIDs. We finally wait for both functions to finish before printing them for the user. + +[Access the Journal By Clicking Here](./anthropic-example-async.ipynb) + +## Tool Example; Cyberware + +In this example, we have the LLM call a simulated tool which gives one random piece of Cyberware based on the user's requested company. From there, the AI tells the user if the cyberware is good for the user's intended purpose. (combatant, hacker, etc.), + +[Access the Journal By Clicking Here](./antrophic-example-tool.ipynb) + + + + + +## Looking for a Barebones, Straight To The Point Journal? + +This journal directly shows the bare basics on using Anthropic and AgentOps! + +> [!WARNING] +> This is mainly recommended for those adept at programming or those who already understand how AgentOps and LLM APIs generally work! + +[Access the Journal By Clicking Here](./anthropic_example.ipynb) + + diff --git a/examples/anthropic_examples/antrophic-example-tool.ipynb b/examples/anthropic_examples/antrophic-example-tool.ipynb new file mode 100644 index 000000000..3c4bb6844 --- /dev/null +++ b/examples/anthropic_examples/antrophic-example-tool.ipynb @@ -0,0 +1 @@ +{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Anthropic supports tools, allowing you to easily connect with different external APIs and the like!\n\nFor this example, we are going to make a tool called \"Cyberware\" which will be our tool; we will create a dummy API that gives specs for cyberware from a specific company before the LLM says if the cyberware is good for a build. To do so, we will use both the tool system and an async function!","metadata":{}},{"cell_type":"markdown","source":"First, we start by importing Agentops and Anthropic","metadata":{}},{"cell_type":"code","source":"!pip install agentops\n!pip install anthropic","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:58:34.878657Z","iopub.execute_input":"2024-11-09T19:58:34.879322Z","iopub.status.idle":"2024-11-09T19:59:00.718845Z","shell.execute_reply.started":"2024-11-09T19:58:34.879282Z","shell.execute_reply":"2024-11-09T19:59:00.717724Z"},"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Collecting agentops\n Downloading agentops-0.3.16-py3-none-any.whl.metadata (24 kB)\nRequirement already satisfied: requests<3.0.0,>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from agentops) (2.32.3)\nCollecting psutil>=5.9.8 (from agentops)\n Downloading psutil-6.1.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (22 kB)\nCollecting packaging==23.2 (from agentops)\n Downloading packaging-23.2-py3-none-any.whl.metadata (3.2 kB)\nRequirement already satisfied: termcolor>=2.3.0 in /opt/conda/lib/python3.10/site-packages (from agentops) (2.4.0)\nRequirement already satisfied: PyYAML<7.0,>=5.3 in /opt/conda/lib/python3.10/site-packages (from agentops) (6.0.2)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (3.3.2)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (3.7)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (1.26.18)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->agentops) (2024.8.30)\nDownloading agentops-0.3.16-py3-none-any.whl (55 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading packaging-23.2-py3-none-any.whl (53 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading psutil-6.1.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (287 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m287.3/287.3 kB\u001b[0m \u001b[31m21.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hInstalling collected packages: psutil, packaging, agentops\n Attempting uninstall: psutil\n Found existing installation: psutil 5.9.3\n Uninstalling psutil-5.9.3:\n Successfully uninstalled psutil-5.9.3\n Attempting uninstall: packaging\n Found existing installation: packaging 21.3\n Uninstalling packaging-21.3:\n Successfully uninstalled packaging-21.3\n\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\ncudf 24.8.3 requires cubinlinker, which is not installed.\ncudf 24.8.3 requires cupy-cuda11x>=12.0.0, which is not installed.\ncudf 24.8.3 requires ptxcompiler, which is not installed.\ncuml 24.8.0 requires cupy-cuda11x>=12.0.0, which is not installed.\ndask-cudf 24.8.3 requires cupy-cuda11x>=12.0.0, which is not installed.\nbeatrix-jupyterlab 2024.66.154055 requires jupyterlab~=3.6.0, but you have jupyterlab 4.2.5 which is incompatible.\ncudf 24.8.3 requires cuda-python<12.0a0,>=11.7.1, but you have cuda-python 12.6.0 which is incompatible.\ndistributed 2024.7.1 requires dask==2024.7.1, but you have dask 2024.9.1 which is incompatible.\ngoogle-cloud-bigquery 2.34.4 requires packaging<22.0dev,>=14.3, but you have packaging 23.2 which is incompatible.\njupyterlab 4.2.5 requires jupyter-lsp>=2.0.0, but you have jupyter-lsp 1.5.1 which is incompatible.\njupyterlab-lsp 5.1.0 requires jupyter-lsp>=2.0.0, but you have jupyter-lsp 1.5.1 which is incompatible.\nlibpysal 4.9.2 requires shapely>=2.0.1, but you have shapely 1.8.5.post1 which is incompatible.\nrapids-dask-dependency 24.8.0a0 requires dask==2024.7.1, but you have dask 2024.9.1 which is incompatible.\nydata-profiling 4.10.0 requires scipy<1.14,>=1.4.1, but you have scipy 1.14.1 which is incompatible.\u001b[0m\u001b[31m\n\u001b[0mSuccessfully installed agentops-0.3.16 packaging-23.2 psutil-5.9.8\nCollecting anthropic\n Downloading anthropic-0.39.0-py3-none-any.whl.metadata (22 kB)\nRequirement already satisfied: anyio<5,>=3.5.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (4.4.0)\nRequirement already satisfied: distro<2,>=1.7.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (1.9.0)\nRequirement already satisfied: httpx<1,>=0.23.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (0.27.0)\nCollecting jiter<1,>=0.4.0 (from anthropic)\n Downloading jiter-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.2 kB)\nRequirement already satisfied: pydantic<3,>=1.9.0 in /opt/conda/lib/python3.10/site-packages (from anthropic) (2.9.2)\nRequirement already satisfied: sniffio in /opt/conda/lib/python3.10/site-packages (from anthropic) (1.3.1)\nRequirement already satisfied: typing-extensions<5,>=4.7 in /opt/conda/lib/python3.10/site-packages (from anthropic) (4.12.2)\nRequirement already satisfied: idna>=2.8 in /opt/conda/lib/python3.10/site-packages (from anyio<5,>=3.5.0->anthropic) (3.7)\nRequirement already satisfied: exceptiongroup>=1.0.2 in /opt/conda/lib/python3.10/site-packages (from anyio<5,>=3.5.0->anthropic) (1.2.0)\nRequirement already satisfied: certifi in /opt/conda/lib/python3.10/site-packages (from httpx<1,>=0.23.0->anthropic) (2024.8.30)\nRequirement already satisfied: httpcore==1.* in /opt/conda/lib/python3.10/site-packages (from httpx<1,>=0.23.0->anthropic) (1.0.5)\nRequirement already satisfied: h11<0.15,>=0.13 in /opt/conda/lib/python3.10/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->anthropic) (0.14.0)\nRequirement already satisfied: annotated-types>=0.6.0 in /opt/conda/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->anthropic) (0.7.0)\nRequirement already satisfied: pydantic-core==2.23.4 in /opt/conda/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->anthropic) (2.23.4)\nDownloading anthropic-0.39.0-py3-none-any.whl (198 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m198.4/198.4 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading jiter-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (327 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m327.5/327.5 kB\u001b[0m \u001b[31m19.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hInstalling collected packages: jiter, anthropic\nSuccessfully installed anthropic-0.39.0 jiter-0.7.0\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Setup our generic default statements","metadata":{}},{"cell_type":"code","source":"from anthropic import Anthropic, AsyncAnthropic\nimport agentops\nimport os\nimport random #We don't need this for agentops, we use this to generate a message later\nimport time #We don't need this for agentops either, we use this when simulating an API later\nimport re #Regex for formatting\nfrom dotenv import load_dotenv","metadata":{"execution":{"iopub.status.busy":"2024-11-09T19:59:59.531722Z","iopub.execute_input":"2024-11-09T19:59:59.532140Z","iopub.status.idle":"2024-11-09T20:00:00.316206Z","shell.execute_reply.started":"2024-11-09T19:59:59.532101Z","shell.execute_reply":"2024-11-09T20:00:00.315436Z"},"trusted":true},"execution_count":4,"outputs":[]},{"cell_type":"markdown","source":"And set our API keys.","metadata":{}},{"cell_type":"code","source":"load_dotenv()\nANTHROPIC_API_KEY = os.getenv(\"ANTHROPIC_API_KEY\") or \"ANTHROPIC API KEY\"\nAGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"AGENTOPS API KEY\"","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:02.860124Z","iopub.execute_input":"2024-11-09T20:00:02.860678Z","iopub.status.idle":"2024-11-09T20:00:02.866414Z","shell.execute_reply.started":"2024-11-09T20:00:02.860635Z","shell.execute_reply":"2024-11-09T20:00:02.865290Z"},"trusted":true},"execution_count":5,"outputs":[]},{"cell_type":"markdown","source":"\nNow let's set the client as Anthropic and start an AgentOps session","metadata":{}},{"cell_type":"code","source":"agentops.init(AGENTOPS_API_KEY, default_tags=[\"anthropic-example-tool\"])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"client = Anthropic(api_key=ANTHROPIC_API_KEY)","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:05.338079Z","iopub.execute_input":"2024-11-09T20:00:05.338711Z","iopub.status.idle":"2024-11-09T20:00:05.354458Z","shell.execute_reply.started":"2024-11-09T20:00:05.338647Z","shell.execute_reply":"2024-11-09T20:00:05.353577Z"},"trusted":true},"execution_count":6,"outputs":[]},{"cell_type":"markdown","source":"Let's create a dummy tool now! First off, let's create a list of companies for the system to choose from","metadata":{}},{"cell_type":"code","source":"Corpo = [\"Kiroshi\", \"Arasaka\", \"Kang Tao\", \"Militech\", \"Biotechnica\", \"Zetatech\", \"Dynalar\"]","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:08.562702Z","iopub.execute_input":"2024-11-09T20:00:08.563085Z","iopub.status.idle":"2024-11-09T20:00:08.569085Z","shell.execute_reply.started":"2024-11-09T20:00:08.563049Z","shell.execute_reply":"2024-11-09T20:00:08.568239Z"},"trusted":true},"execution_count":9,"outputs":[]},{"cell_type":"markdown","source":"And now we create a DB! This could be anything from an .xml/.json to Postgres or MySQL! For our intent of a test, we will just include a dictionary.","metadata":{}},{"cell_type":"code","source":"cyberware_list = [\n {\n \"name\": \"Kiroshi Optics\",\n \"creator\": \"Kiroshi\",\n \"bio\": \"Advanced cybernetic eye implants providing enhanced vision, a heads-up display (HUD), and scanning capabilities.\",\n \"stats\": {\n \"vision_modes\": [\"Thermal\", \"Night Vision\", \"Zoom\"],\n \"target_analysis\": \"Enemy Weak Spots Highlighted\"\n }\n },\n {\n \"name\": \"Gorilla Arms\",\n \"creator\": \"Arasaka\",\n \"bio\": \"Mechanical arms designed to enhance physical strength, allowing for powerful melee attacks and the ability to rip open doors.\",\n \"stats\": {\n \"melee_damage_bonus\": \"+100%\",\n \"strength_check_bonus\": \"+20\"\n }\n },\n {\n \"name\": \"Mantis Blades\",\n \"creator\": \"Arasaka\",\n \"bio\": \"Arm-mounted blades used for close combat, retractable from the forearms and capable of delivering high-speed slashes.\",\n \"stats\": {\n \"damage_type\": \"Physical\",\n \"attack_speed\": \"+30%\",\n \"bleed_chance\": \"50%\"\n }\n },\n {\n \"name\": \"Monowire\",\n \"creator\": \"Kang Tao\",\n \"bio\": \"A high-tech fiber-optic whip weapon that can slice through enemies with ease and can be charged for extra damage.\",\n \"stats\": {\n \"damage_type\": \"Physical/Electrical\",\n \"charge_bonus_damage\": \"+200%\",\n \"range\": \"5 meters\"\n }\n },\n {\n \"name\": \"Projectile Launch System\",\n \"creator\": \"Militech\",\n \"bio\": \"An arm-mounted cannon that allows the user to launch various types of projectiles, including grenades and explosive rounds.\",\n \"stats\": {\n \"ammo_types\": [\"Explosive\", \"Incendiary\", \"EMP\"],\n \"blast_radius\": \"3 meters\"\n }\n },\n {\n \"name\": \"Syn-Lungs\",\n \"creator\": \"Biotechnica\",\n \"bio\": \"Synthetic lungs that improve the user's breathing efficiency and stamina, allowing for prolonged physical exertion.\",\n \"stats\": {\n \"stamina_regen_rate\": \"+25%\",\n \"oxygen_capacity\": \"+30%\"\n }\n },\n {\n \"name\": \"Reinforced Tendons\",\n \"creator\": \"Arasaka\",\n \"bio\": \"Muscular enhancements that allow the user to jump higher and perform acrobatic movements.\",\n \"stats\": {\n \"jump_height\": \"+2 meters\",\n \"stamina_cost_reduction\": \"20%\"\n }\n },\n {\n \"name\": \"Bionic Joints\",\n \"creator\": \"Zetatech\",\n \"bio\": \"Cybernetic enhancements to the joints, providing increased flexibility and limb strength.\",\n \"stats\": {\n \"mobility_increase\": \"+15%\",\n \"limb_strength\": \"+20\"\n }\n },\n {\n \"name\": \"Subdermal Armor\",\n \"creator\": \"Militech\",\n \"bio\": \"Under-the-skin armor implants that increase the user's resistance to damage.\",\n \"stats\": {\n \"armor_bonus\": \"+200\",\n \"damage_resistance\": \"20%\"\n }\n },\n {\n \"name\": \"Sandevistan\",\n \"creator\": \"Dynalar\",\n \"bio\": \"Reflex booster that slows down time for the user, allowing them to move at superhuman speed.\",\n \"stats\": {\n \"duration\": \"8 seconds\",\n \"cooldown\": \"30 seconds\",\n \"speed_increase\": \"+50%\"\n }\n },\n {\n \"name\": \"Berserk\",\n \"creator\": \"Arasaka\",\n \"bio\": \"An adrenaline-inducing cyberware that temporarily boosts the user's physical capabilities, including strength and damage resistance.\",\n \"stats\": {\n \"duration\": \"10 seconds\",\n \"strength_bonus\": \"+30\",\n \"damage_reduction\": \"15%\"\n }\n },\n {\n \"name\": \"Cyberdeck\",\n \"creator\": \"NetWatch\",\n \"bio\": \"Cybernetic interface used for hacking, allowing the user to deploy quickhacks and breach enemy systems.\",\n \"stats\": {\n \"RAM_slots\": \"8\",\n \"quickhack_upload_speed\": \"+30%\"\n }\n },\n {\n \"name\": \"Pain Editor\",\n \"creator\": \"Biotechnica\",\n \"bio\": \"A neurological implant that reduces the perception of pain, allowing the user to endure more damage.\",\n \"stats\": {\n \"damage_taken_reduction\": \"10%\",\n \"bleed_resistance\": \"+50%\"\n }\n },\n {\n \"name\": \"Blood Pump\",\n \"creator\": \"Arasaka\",\n \"bio\": \"An enhanced circulatory system that improves health regeneration during combat.\",\n \"stats\": {\n \"health_regen_per_second\": \"+5%\",\n \"activation_duration\": \"6 seconds\"\n }\n },\n {\n \"name\": \"Heal-On-Kill\",\n \"creator\": \"Militech\",\n \"bio\": \"A system that restores a portion of the user's health each time they defeat an enemy.\",\n \"stats\": {\n \"health_restored_per_kill\": \"20%\",\n \"cooldown\": \"3 seconds\"\n }\n },\n {\n \"name\": \"Smart Link\",\n \"creator\": \"Kang Tao\",\n \"bio\": \"A wrist implant that increases smart weapon accuracy and locks onto targets for better aim.\",\n \"stats\": {\n \"smart_weapon_accuracy\": \"+15%\",\n \"target_lock_speed\": \"+25%\"\n }\n },\n {\n \"name\": \"Nano Relays\",\n \"creator\": \"Zetatech\",\n \"bio\": \"Enhances the duration of Sandevistan or Berserk by boosting neural signal transmission.\",\n \"stats\": {\n \"duration_increase\": \"+2 seconds\"\n }\n },\n {\n \"name\": \"Optical Camo\",\n \"creator\": \"Militech\",\n \"bio\": \"A cloaking device that provides temporary invisibility to the user.\",\n \"stats\": {\n \"invisibility_duration\": \"10 seconds\",\n \"cooldown\": \"30 seconds\"\n }\n },\n {\n \"name\": \"Bioconductor\",\n \"creator\": \"Biotechnica\",\n \"bio\": \"Regulates the body’s internal processes, reducing cyberware cooldowns.\",\n \"stats\": {\n \"cooldown_reduction\": \"20%\"\n }\n },\n {\n \"name\": \"Second Heart\",\n \"creator\": \"Biotechnica\",\n \"bio\": \"A failsafe biological implant that revives the user once when they die.\",\n \"stats\": {\n \"revive_health\": \"50%\",\n \"cooldown\": \"2 minutes\"\n }\n },\n {\n \"name\": \"Biomonitor\",\n \"creator\": \"Arasaka\",\n \"bio\": \"Monitors the user's vital signs and triggers healing if health drops too low.\",\n \"stats\": {\n \"activation_threshold\": \"15% health\",\n \"healing_amount\": \"30%\"\n }\n },\n {\n \"name\": \"Neofiber\",\n \"creator\": \"Zetatech\",\n \"bio\": \"A muscle fiber enhancement that increases evasion and movement speed.\",\n \"stats\": {\n \"evasion_increase\": \"+10%\",\n \"movement_speed_bonus\": \"+5%\"\n }\n },\n {\n \"name\": \"Cataresist\",\n \"creator\": \"Biotechnica\",\n \"bio\": \"Improves the user's resistance to toxins and shock-based damage.\",\n \"stats\": {\n \"poison_resistance\": \"+30%\",\n \"shock_resistance\": \"+25%\"\n }\n },\n {\n \"name\": \"Microgenerator\",\n \"creator\": \"Militech\",\n \"bio\": \"Releases a shockwave when the user takes damage, knocking back enemies.\",\n \"stats\": {\n \"shockwave_radius\": \"3 meters\",\n \"cooldown\": \"10 seconds\"\n }\n },\n {\n \"name\": \"Fortified Ankles\",\n \"creator\": \"Dynalar\",\n \"bio\": \"Reinforces the legs to allow for charged jumps and enhanced mobility.\",\n \"stats\": {\n \"charged_jump_height\": \"+3 meters\",\n \"stamina_cost\": \"15%\"\n }\n },\n {\n \"name\": \"Reflex Tuner\",\n \"creator\": \"Arasaka\",\n \"bio\": \"Slows time when the user's health falls below a certain level, providing a brief window for recovery.\",\n \"stats\": {\n \"activation_threshold\": \"25% health\",\n \"duration\": \"5 seconds\"\n }\n },\n {\n \"name\": \"Techgogs\",\n \"creator\": \"Kiroshi\",\n \"bio\": \"Enhanced goggles that provide better target acquisition and analysis.\",\n \"stats\": {\n \"targeting_accuracy\": \"+20%\",\n \"analyze_speed\": \"+25%\"\n }\n }\n]\n","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:32:14.377202Z","iopub.execute_input":"2024-11-09T20:32:14.377597Z","iopub.status.idle":"2024-11-09T20:32:14.402830Z","shell.execute_reply.started":"2024-11-09T20:32:14.377561Z","shell.execute_reply":"2024-11-09T20:32:14.401893Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":55,"outputs":[]},{"cell_type":"markdown","source":"And finally we make build types! We will keep to 6 based off the Edgerunners anime! (Try guessing which archetype is who)","metadata":{}},{"cell_type":"code","source":"edgerunners_builds = [\n {\n \"name\": \"The Agile Fighter\",\n \"description\": \"An adaptable build that focuses on speed and reflexes. Excelling in close-quarters combat, this fighter utilizes a mix of melee and ranged weapons, quickly adapting to any situation and embodying the spirit of a street fighter.\"\n },\n {\n \"name\": \"The Chaotic Gunner\",\n \"description\": \"An unpredictable build specializing in dual-wielding firearms and fast-paced combat. With high energy and a penchant for mayhem, this gunner overwhelms enemies with speed and accuracy, making them a force to be reckoned with in any firefight.\"\n },\n {\n \"name\": \"The Heavy Brawler\",\n \"description\": \"A build centered around strength and durability, combining powerful weaponry with advanced cybernetic enhancements. This brawler can absorb damage and unleash devastating attacks, making them a formidable frontline combatant.\"\n },\n {\n \"name\": \"The Stealth Hacker\",\n \"description\": \"A stealthy and agile build focused on evasion and hacking. Utilizing advanced cyberware, this infiltrator manipulates the environment and sneaks past enemy lines without detection, excelling in covert operations.\"\n },\n {\n \"name\": \"The Tactical Defender\",\n \"description\": \"A defensive build that excels in protecting allies and providing support on the battlefield. With resilience and tactical prowess, this defender can absorb enemy fire while counterattacking, ideal for players who prefer a supportive role.\"\n },\n {\n \"name\": \"The Supportive Strategist\",\n \"description\": \"A build focused on enhancing team performance. Utilizing a mix of hacking and buffing skills, this strategist provides advantages in combat, ensuring that allies remain strong and focused during engagements.\"\n }\n]\n","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:14.284254Z","iopub.execute_input":"2024-11-09T20:00:14.285035Z","iopub.status.idle":"2024-11-09T20:00:14.291284Z","shell.execute_reply.started":"2024-11-09T20:00:14.284994Z","shell.execute_reply":"2024-11-09T20:00:14.290236Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":11,"outputs":[]},{"cell_type":"markdown","source":"Now that that's done, we can make a function! We will take the input from the user; for this test, we can assume we will always get a proper corpo name. We have a two second wait to simulate an online API request","metadata":{}},{"cell_type":"code","source":"def get_cyberware_by_creator(creator_name):\n # Filter the items by creator name (case-insensitive)\n filtered_items = [item for item in cyberware_list if item[\"creator\"].lower() == creator_name.lower()]\n \n # If there are no items found, handle it appropriately\n if not filtered_items:\n return \"No cyberware found for this creator.\"\n \n # Select a random item from the filtered list\n returned_item = random.choice(filtered_items)\n \n # Pause for 2 seconds (simulate some kind of delay)\n time.sleep(2)\n \n # Create a final formatted string to return\n final = f'Name: {returned_item[\"name\"]}, Creator: {returned_item[\"creator\"]}, Bio: {returned_item[\"bio\"]}, Stats: {returned_item[\"stats\"]}'\n \n return final","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:23.149239Z","iopub.execute_input":"2024-11-09T20:00:23.150097Z","iopub.status.idle":"2024-11-09T20:00:23.157206Z","shell.execute_reply.started":"2024-11-09T20:00:23.150045Z","shell.execute_reply":"2024-11-09T20:00:23.156013Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":13,"outputs":[]},{"cell_type":"code","source":"get_cyberware_by_creator(\"Militech\")","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:29.288885Z","iopub.execute_input":"2024-11-09T20:00:29.289810Z","iopub.status.idle":"2024-11-09T20:00:31.298240Z","shell.execute_reply.started":"2024-11-09T20:00:29.289769Z","shell.execute_reply":"2024-11-09T20:00:31.297326Z"},"trusted":true},"execution_count":14,"outputs":[{"execution_count":14,"output_type":"execute_result","data":{"text/plain":"\"Name: Projectile Launch System, Creator: Militech, Bio: An arm-mounted cannon that allows the user to launch various types of projectiles, including grenades and explosive rounds., Stats: {'ammo_types': ['Explosive', 'Incendiary', 'EMP'], 'blast_radius': '3 meters'}\""},"metadata":{}}]},{"cell_type":"markdown","source":"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!\n\nWe 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","metadata":{}},{"cell_type":"markdown","source":"Now we make a message!","metadata":{}},{"cell_type":"code","source":"#We make our history a separate block to be easier to add to and get a random build to begin\n\n# Get a random build\nrandom_build = random.choice(edgerunners_builds)\n\n# We make our history a separate block to be easier to add to and get a random build to begin\ninitialmessages = [\n {\n \"role\": \"user\",\n \"content\": \"The Heavy Tank - This build focuses on durability and defense, sacrificing speed for maximum resilience. Ideal for handling sustained combat and enduring powerful hits. Requested corporation is Arasaka.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Starting Search! get_cyberware_by_creator[Arasaka]\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Name: Reinforced Subdermal Armor, Creator: Arasaka, Bio: Provides additional layers of armor under the skin to absorb heavy impact, Stats: +50% physical damage resistance, -10% agility\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"The Reinforced Subdermal Armor is a solid choice for The Heavy Tank build. The additional 50% damage resistance will allow you to endure powerful attacks, which is perfect for your defensive style. Be aware of the slight agility decrease, though it aligns with your build's focus on resilience over speed.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"The Silent Assassin - A stealth-focused build that emphasizes silent takedowns and avoiding detection. This assassin utilizes a combination of stealth and high precision in ranged combat. Requested corporation is Militech.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Starting Search! get_cyberware_by_creator[Militech]\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Name: Optical Camouflage System, Creator: Militech, Bio: A cloaking system that renders the user nearly invisible for a short duration, Stats: Duration: 10 seconds, Cooldown: 40 seconds\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"The Optical Camouflage System is highly suitable for The Silent Assassin build. Its invisibility feature will allow you to bypass enemies and perform stealth takedowns without being noticed. Just be cautious of its cooldown and plan your escape if needed.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"The Tech Savant - A build that excels in using advanced technology and gadgets, specializing in hacking and controlling devices. This tech expert uses drones and automated turrets in combat. Requested corporation is Zetatech.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Starting Search! get_cyberware_by_creator[Zetatech]\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Name: Drone Control Interface, Creator: Zetatech, Bio: Allows the user to control multiple drones simultaneously and provides an enhanced HUD for drone operations, Stats: Drone Capacity: +2, HUD enhancement for better drone tracking\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"The Drone Control Interface is ideal for The Tech Savant build, as it increases your ability to control multiple drones and improves your situational awareness through the enhanced HUD. This item will amplify your tech-based combat strategy significantly.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"The Cyber Sniper - A long-range build specializing in precision and high-damage shots from a distance. This sniper focuses on accuracy and stability. Requested corporation is Kang Tao.\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Starting Search! get_cyberware_by_creator[Kang Tao]\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"Name: Stabilizer Arms, Creator: Kang Tao, Bio: Cybernetic arms with built-in stabilizers to reduce weapon sway, Stats: Recoil Reduction: 80%, Increased Precision: +30%\"\n },\n {\n \"role\": \"assistant\",\n \"content\": \"The Stabilizer Arms are an excellent choice for The Cyber Sniper. The enhanced precision and recoil reduction will improve your accuracy, making it easier to land precise, high-damage shots from long range. Perfect for maintaining a steady aim during extended engagements.\"\n },\n {\n \"role\": \"user\",\n \"content\": f\"Based on the user's build type and requested corporation, get a random item from the corporation and tell if it will be a good idea to use; {random_build['name']} - {random_build['description']}, Requested Coroporation is {random.choice(Corpo)}\"\n }\n]\n","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:34.415063Z","iopub.execute_input":"2024-11-09T20:00:34.415759Z","iopub.status.idle":"2024-11-09T20:00:34.426528Z","shell.execute_reply.started":"2024-11-09T20:00:34.415719Z","shell.execute_reply":"2024-11-09T20:00:34.425555Z"},"trusted":true},"execution_count":15,"outputs":[]},{"cell_type":"markdown","source":"For now, this is where we will talk to the LLM! Stream on seems to have a few problems so we get the output as one chunk! ","metadata":{}},{"cell_type":"code","source":"response = client.messages.create(\n max_tokens=5000,\n model=\"claude-3-5-sonnet-20240620\",\n tools=[{\n \"name\": \"get_cyberware_by_creator\",\n \"description\": \"Retrieve cyberware information based on the manufacturer corporation\",\n \"input_schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"creator\": {\"type\": \"string\", \"description\": \"The name of the cyberware creator\"}\n },\n \"required\": [\"creator\"]\n },\n }],\n messages=initialmessages\n)\n\nprint(response)","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:00:38.500148Z","iopub.execute_input":"2024-11-09T20:00:38.500868Z","iopub.status.idle":"2024-11-09T20:00:41.670002Z","shell.execute_reply.started":"2024-11-09T20:00:38.500827Z","shell.execute_reply":"2024-11-09T20:00:41.669032Z"},"trusted":true},"execution_count":16,"outputs":[{"name":"stdout","text":"Message(id='msg_01Afykywq3GD2EoHaGGxujRy', content=[TextBlock(text=\"Certainly! Let's see what Zetatech has to offer for The Stealth Hacker build. I'll retrieve a random item from Zetatech and evaluate its suitability for your build.\", type='text'), ToolUseBlock(id='toolu_011JwtgPzy3a88NR1s9BmgNL', input={'creator': 'Zetatech'}, name='get_cyberware_by_creator', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=Usage(input_tokens=1206, output_tokens=109))\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Now to get the tool used! We know it will be used and can pretty much ignore the AI's text, still let's show it anyways! We are going to see if the tool name is called get_cyberware_by_creator (And we know it's going to %99 be there)","metadata":{}},{"cell_type":"code","source":"SearchResult = \"\"\n\n# Print response content to see the data\nprint(response.content)\n\n# Assuming ToolUseBlock is at index 1\ntool_use_block = response.content[1]\n\n# Get the tool name and input\ntool_name = tool_use_block.name\ntool_input = tool_use_block.input\n\n# Extract creator (e.g., 'Militech')\ntool_creator = tool_input['creator']\n\n# Check if the tool name is \"get_cyberware_by_creator\"\nif tool_name == \"get_cyberware_by_creator\":\n # Call the function with the tool creator as an argument\n SearchResult = get_cyberware_by_creator(tool_creator)\n ","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:23:38.711588Z","iopub.execute_input":"2024-11-09T20:23:38.711991Z","iopub.status.idle":"2024-11-09T20:23:40.718852Z","shell.execute_reply.started":"2024-11-09T20:23:38.711953Z","shell.execute_reply":"2024-11-09T20:23:40.718027Z"},"trusted":true},"execution_count":47,"outputs":[{"name":"stdout","text":"[TextBlock(text=\"Certainly! Let's see what Zetatech has to offer for The Stealth Hacker build. I'll retrieve a random item from Zetatech and evaluate its suitability for your build.\", type='text'), ToolUseBlock(id='toolu_011JwtgPzy3a88NR1s9BmgNL', input={'creator': 'Zetatech'}, name='get_cyberware_by_creator', type='tool_use')]\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Now, we will add an item to the history and create our next request!","metadata":{}},{"cell_type":"code","source":"initialmessages.append({\n \"role\": \"assistant\",\n \"content\": SearchResult\n})\n\ninitialmessages.append({\n \"role\": \"user\",\n \"content\": \"Is this a good match?\"\n})","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:24:59.776900Z","iopub.execute_input":"2024-11-09T20:24:59.777625Z","iopub.status.idle":"2024-11-09T20:24:59.782123Z","shell.execute_reply.started":"2024-11-09T20:24:59.777585Z","shell.execute_reply":"2024-11-09T20:24:59.781171Z"},"trusted":true},"execution_count":49,"outputs":[]},{"cell_type":"markdown","source":"Now let's see if this is good!","metadata":{}},{"cell_type":"code","source":"response = client.messages.create(\n max_tokens=5000,\n model=\"claude-3-5-sonnet-20240620\",\n tools=[{\n \"name\": \"get_cyberware_by_creator\",\n \"description\": \"Retrieve cyberware information based on the manufacturer corporation\",\n \"input_schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"creator\": {\"type\": \"string\", \"description\": \"The name of the cyberware creator\"}\n },\n \"required\": [\"creator\"]\n },\n }],\n messages=initialmessages\n)\n\nprint(response)","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:25:02.862732Z","iopub.execute_input":"2024-11-09T20:25:02.863142Z","iopub.status.idle":"2024-11-09T20:25:12.630165Z","shell.execute_reply.started":"2024-11-09T20:25:02.863103Z","shell.execute_reply":"2024-11-09T20:25:12.629235Z"},"trusted":true},"execution_count":50,"outputs":[{"name":"stdout","text":"Message(id='msg_01YWrpDbF475reehYXHNv7nE', content=[TextBlock(text='Yes, the Neofiber cyberware from Zetatech is an excellent match for The Stealth Hacker build you described. Let\\'s break down why:\\n\\n1. Alignment with build focus: The Stealth Hacker is described as a \"stealthy and agile build focused on evasion.\" The Neofiber directly enhances both stealth and agility aspects of this build.\\n\\n2. Evasion increase: The +10% evasion increase is particularly valuable for a character that aims to avoid detection and enemy attacks. This will make it easier to sneak past enemy lines and escape if spotted.\\n\\n3. Movement speed bonus: The +5% movement speed bonus complements the build\\'s agility focus. Faster movement allows for quicker repositioning, easier escapes, and more efficient navigation through complex environments during covert operations.\\n\\n4. Synergy with hacking: While this cyberware doesn\\'t directly enhance hacking abilities, the improved evasion and speed will help the character get into optimal positions for hacking operations and quickly retreat if necessary.\\n\\n5. Non-interference with stealth: Unlike some combat-focused cyberware that might be noisy or visually obvious, this muscle fiber enhancement is subtle and won\\'t compromise the character\\'s ability to remain undetected.\\n\\n6. Correct corporation: The item is from Zetatech, which matches the requested corporation.\\n\\nOverall, the Neofiber cyberware enhances the core aspects of The Stealth Hacker build - stealth, agility, and evasion. It will allow the character to move more quickly and avoid detection more effectively, which is crucial for an infiltrator focused on covert operations. This cyberware provides a solid foundation for the build, leaving room for additional hacking-specific augmentations to round out the character\\'s capabilities.', type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=1385, output_tokens=408))\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Now to display the output!","metadata":{}},{"cell_type":"code","source":"message = response.content[0].text\nprint(message)","metadata":{"execution":{"iopub.status.busy":"2024-11-09T20:30:57.591539Z","iopub.execute_input":"2024-11-09T20:30:57.591951Z","iopub.status.idle":"2024-11-09T20:30:57.597218Z","shell.execute_reply.started":"2024-11-09T20:30:57.591906Z","shell.execute_reply":"2024-11-09T20:30:57.596320Z"},"trusted":true},"execution_count":54,"outputs":[{"name":"stdout","text":"Yes, the Neofiber cyberware from Zetatech is an excellent match for The Stealth Hacker build you described. Let's break down why:\n\n1. Alignment with build focus: The Stealth Hacker is described as a \"stealthy and agile build focused on evasion.\" The Neofiber directly enhances both stealth and agility aspects of this build.\n\n2. Evasion increase: The +10% evasion increase is particularly valuable for a character that aims to avoid detection and enemy attacks. This will make it easier to sneak past enemy lines and escape if spotted.\n\n3. Movement speed bonus: The +5% movement speed bonus complements the build's agility focus. Faster movement allows for quicker repositioning, easier escapes, and more efficient navigation through complex environments during covert operations.\n\n4. Synergy with hacking: While this cyberware doesn't directly enhance hacking abilities, the improved evasion and speed will help the character get into optimal positions for hacking operations and quickly retreat if necessary.\n\n5. Non-interference with stealth: Unlike some combat-focused cyberware that might be noisy or visually obvious, this muscle fiber enhancement is subtle and won't compromise the character's ability to remain undetected.\n\n6. Correct corporation: The item is from Zetatech, which matches the requested corporation.\n\nOverall, the Neofiber cyberware enhances the core aspects of The Stealth Hacker build - stealth, agility, and evasion. It will allow the character to move more quickly and avoid detection more effectively, which is crucial for an infiltrator focused on covert operations. This cyberware provides a solid foundation for the build, leaving room for additional hacking-specific augmentations to round out the character's capabilities.\n","output_type":"stream"}]},{"cell_type":"markdown","source":"Run this to end the session!","metadata":{}},{"cell_type":"code","source":"agentops.end_session(\"Success\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]} \ No newline at end of file