Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions 01_ai_agents_first/15_run_lifecycle/run_lifecycle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": null,
"metadata": {
"id": "xL1SE0WBzNfB"
},
Expand All @@ -133,7 +133,8 @@
"import random\n",
"from typing import Any\n",
"\n",
"from agents import Agent, RunContextWrapper, RunHooks, Runner, Tool, Usage, function_tool"
"from agents import Agent, RunContextWrapper, RunHooks, Runner, Tool, Usage, function_tool\n",
"import sys"
]
},
{
Expand Down Expand Up @@ -289,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -323,17 +324,21 @@
"\n",
"\n",
"@function_tool(\"random_number\")\n",
"def random_number(max: int) -> int:\n",
" \"\"\"Generate a random number up to the provided max.\"\"\"\n",
" return random.randint(0, max)\n",
"def random_number(max_value: int) -> int:\n",
" \"\"\"Generate a random number between 0 and the provided max_value (inclusive).\"\"\"\n",
" return random.randint(0, max_value)\n",
"\n",
"\n",
"# Safer tool usage and prevents bugs if wrong type is passed.\n",
"@function_tool(\"multiply_by_two\")\n",
"def multiply_by_two(x: int) -> int:\n",
" \"\"\"Return x times two.\"\"\"\n",
" if not isinstance(x, int):\n",
" raise ValueError(\"Expected integer input.\")\n",
" return x * 2\n",
"\n",
"\n",
"\n",
"multiply_agent = Agent(\n",
" name=\"Multiply Agent\",\n",
" instructions=\"Multiply the number by 2 and then return the final result.\",\n",
Expand Down