{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "\n", "AgentChat provides intuitive defaults, such as **Agents** with preset behaviors and **Teams** with predefined communication protocols, to simplify building multi-agent applications.\n", "\n", ":::{note}\n", "For installation instructions, please refer to the [installation guide](../installation.md).\n", ":::\n", "\n", "\n", "## Defining a Model Client \n", "\n", "In many cases, an agent will require access to a generative model. AgentChat utilizes the model clients provided by the [ `autogen-core`](../../core-user-guide/framework/model-clients.ipynb) package to access models." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CreateResult(finish_reason='stop', content='The capital of France is Paris.', usage=RequestUsage(prompt_tokens=15, completion_tokens=7), cached=False, logprobs=None)\n" ] } ], "source": [ "from autogen_core.components.models import OpenAIChatCompletionClient, UserMessage\n", "\n", "# Create an OpenAI model client.\n", "model_client = OpenAIChatCompletionClient(\n", " model=\"gpt-4o-2024-08-06\",\n", " # api_key=\"sk-...\", # Optional if you have an OPENAI_API_KEY env variable set.\n", ")\n", "model_client_result = await model_client.create(\n", " messages=[\n", " UserMessage(content=\"What is the capital of France?\", source=\"user\"),\n", " ]\n", ")\n", "print(model_client_result) # \"Paris\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Handling Logs\n", "\n", "As agents interact with each other, they generate logs that can be useful in building and debugging multi-agent systems. Your application can consume these logs by attaching a log handler to the AgentChat events. AgentChat also provides a default log handler that writes logs to the console and file.\n", "\n", "Attache the log handler before running your application to view agent message logs. \n", "\n", "```{tip}\n", "You can implement your own log handler and attach it to the AgentChat events.\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import logging\n", "\n", "from autogen_agentchat import EVENT_LOGGER_NAME\n", "from autogen_agentchat.logging import ConsoleLogHandler\n", "\n", "logger = logging.getLogger(EVENT_LOGGER_NAME)\n", "logger.addHandler(ConsoleLogHandler())\n", "logger.setLevel(logging.INFO)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Whats Next ?\n", "\n", "Now that we have installed the `autogen-agentchat` package, let's move on to exploring how to build agents using the agent presets provided by the package." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.12.6" } }, "nbformat": 4, "nbformat_minor": 2 }