mirror of
https://github.com/microsoft/autogen.git
synced 2025-12-24 21:49:42 +00:00
Update references in docs (#4590)
* Update agent doc * Remove outdated doc * Update references * Update readme * Update readme
This commit is contained in:
parent
fa550c2c36
commit
8dac072658
@ -10,7 +10,7 @@ from typing import List
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, TopicId
|
||||
from autogen_core import SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core.components.models import (
|
||||
ChatCompletionClient,
|
||||
UserMessage,
|
||||
|
||||
@ -10,7 +10,7 @@ from typing import List
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, TopicId
|
||||
from autogen_core import SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
from autogen_core.components.models import (
|
||||
ChatCompletionClient,
|
||||
ModelCapabilities,
|
||||
|
||||
@ -3,7 +3,7 @@ import logging
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, TopicId
|
||||
from autogen_core import SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
from autogen_core import DefaultSubscription, DefaultTopicId
|
||||
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
|
||||
from autogen_core.components.models import (
|
||||
|
||||
@ -9,7 +9,7 @@ from typing import Any, Dict, List, Tuple, Union
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, TopicId
|
||||
from autogen_core import SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
from autogen_core import DefaultSubscription, DefaultTopicId
|
||||
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
|
||||
from autogen_core.components.models import (
|
||||
|
||||
@ -1,9 +1,3 @@
|
||||
# AutoGen AgentChat
|
||||
|
||||
- [Documentation](https://microsoft.github.io/autogen/dev/user-guide/agentchat-user-guide/index.html)
|
||||
|
||||
## Package structure
|
||||
|
||||
- `agents` are the building blocks for creating agents and built-in agents.
|
||||
- `teams` are the building blocks for creating teams of agents and built-in teams, such as group chats.
|
||||
- `logging` contains logging utilities.
|
||||
@ -1,9 +1,3 @@
|
||||
# AutoGen Core
|
||||
|
||||
- [Documentation](https://microsoft.github.io/autogen/dev/user-guide/core-user-guide/index.html)
|
||||
|
||||
## Package layering
|
||||
|
||||
- `base` are the the foundational generic interfaces upon which all else is built. This module must not depend on any other module.
|
||||
- `application` are implementations of core components that are used to compose an application.
|
||||
- `components` are the building blocks for creating agents.
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
<mxfile host="app.diagrams.net" modified="2024-07-11T07:42:49.053Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0" etag="OK-OoeWcNWr8T5Wb_Dpd" version="24.6.4" type="device">
|
||||
<diagram name="Page-1" id="cddb7oONEilqIw1Y7nf5">
|
||||
<mxGraphModel dx="748" dy="690" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-12" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" parent="1" vertex="1">
|
||||
<mxGeometry x="160" y="240" width="260" height="230" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-1" value="<b>Core:</b> Agent and Agent Runtime" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;" parent="1" vertex="1">
|
||||
<mxGeometry x="170" y="380" width="240" height="50" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-2" value="<b>AI Components: </b>Base Agents, Models, Tools, Memory, etc." style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="170" y="250" width="240" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-4" value="<b>Application Components</b>: Runtime Implementations, Loggings, etc." style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
|
||||
<mxGeometry x="170" y="320" width="240" height="50" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-6" value="Multi-Agent Applications" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" vertex="1">
|
||||
<mxGeometry x="170" y="183" width="240" height="50" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e_Se_iOjKQHndGvTYtJ0-10" value="AutoGen" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="436" width="60" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
@ -188,8 +188,10 @@
|
||||
"The following preset agents are available:\n",
|
||||
"\n",
|
||||
"- {py:class}`~autogen_agentchat.agents.CodeExecutorAgent`: An agent that can execute code.\n",
|
||||
"- {py:class}`~autogen_ext.agents.OpenAIAssistantAgent`: An agent that is backed by an OpenAI Assistant, with ability to use custom tools.\n",
|
||||
"- {py:class}`~autogen_ext.agents.MultimodalWebSurfer`: A multi-modal agent that can search the web and visit web pages for information."
|
||||
"- {py:class}`~autogen_ext.agents.openai.OpenAIAssistantAgent`: An agent that is backed by an OpenAI Assistant, with ability to use custom tools.\n",
|
||||
"- {py:class}`~autogen_ext.agents.web_surfer.MultimodalWebSurfer`: A multi-modal agent that can search the web and visit web pages for information.\n",
|
||||
"- {py:class}`~autogen_ext.agents.file_surfer.FileSurfer`: An agent that can search and browse local files for information.\n",
|
||||
"- {py:class}`~autogen_ext.agents.video_surfer.VideoSurfer`: An agent that can watch videos for information."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -248,7 +250,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.6"
|
||||
"version": "3.11.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@ -8,42 +8,23 @@
|
||||
"\n",
|
||||
"The model clients included in AutoGen emit structured events that can be used to track the usage of the model. This notebook demonstrates how to use the logger to track the usage of the model.\n",
|
||||
"\n",
|
||||
"These events are logged to the logger with the name: :py:attr:`autogen_core.application.logging.EVENT_LOGGER_NAME`."
|
||||
"These events are logged to the logger with the name: :py:attr:`autogen_core.EVENT_LOGGER_NAME`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import logging\n",
|
||||
"\n",
|
||||
"from autogen_core.application.logging.events import LLMCallEvent\n",
|
||||
"from autogen_core.logging import LLMCallEvent\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class LLMUsageTracker(logging.Handler):\n",
|
||||
" def __init__(self) -> None:\n",
|
||||
" \"\"\"Logging handler that tracks the number of tokens used in the prompt and completion.\n",
|
||||
"\n",
|
||||
" Example:\n",
|
||||
"\n",
|
||||
" .. code-block:: python\n",
|
||||
"\n",
|
||||
" from autogen_core.application.logging import LLMUsageTracker, EVENT_LOGGER_NAME\n",
|
||||
"\n",
|
||||
" # Set up the logging configuration to use the custom handler\n",
|
||||
" logger = logging.getLogger(EVENT_LOGGER_NAME)\n",
|
||||
" logger.setLevel(logging.INFO)\n",
|
||||
" llm_usage = LLMUsageTracker()\n",
|
||||
" logger.handlers = [llm_usage]\n",
|
||||
"\n",
|
||||
" # ...\n",
|
||||
"\n",
|
||||
" print(llm_usage.prompt_tokens)\n",
|
||||
" print(llm_usage.completion_tokens)\n",
|
||||
"\n",
|
||||
" \"\"\"\n",
|
||||
" \"\"\"Logging handler that tracks the number of tokens used in the prompt and completion.\"\"\"\n",
|
||||
" super().__init__()\n",
|
||||
" self._prompt_tokens = 0\n",
|
||||
" self._completion_tokens = 0\n",
|
||||
@ -89,7 +70,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from autogen_core.application.logging import EVENT_LOGGER_NAME\n",
|
||||
"from autogen_core import EVENT_LOGGER_NAME\n",
|
||||
"\n",
|
||||
"# Set up the logging configuration to use the custom handler\n",
|
||||
"logger = logging.getLogger(EVENT_LOGGER_NAME)\n",
|
||||
@ -120,7 +101,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.5"
|
||||
"version": "3.11.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@ -1,179 +1,179 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Termination using Intervention Handler\n",
|
||||
"\n",
|
||||
"```{note}\n",
|
||||
"This method is valid when using {py:class}`~autogen_core.application.SingleThreadedAgentRuntime`.\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"There are many different ways to handle termination in `autogen_core`. Ultimately, the goal is to detect that the runtime no longer needs to be executed and you can proceed to finalization tasks. One way to do this is to use an {py:class}`autogen_core.base.intervention.InterventionHandler` to detect a termination message and then act on it."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from dataclasses import dataclass\n",
|
||||
"from typing import Any\n",
|
||||
"\n",
|
||||
"from autogen_core import (\n",
|
||||
" AgentId,\n",
|
||||
" DefaultTopicId,\n",
|
||||
" MessageContext,\n",
|
||||
" RoutedAgent,\n",
|
||||
" SingleThreadedAgentRuntime,\n",
|
||||
" default_subscription,\n",
|
||||
" message_handler,\n",
|
||||
")\n",
|
||||
"from autogen_core.base.intervention import DefaultInterventionHandler"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"First, we define a dataclass for regular message and message that will be used to signal termination."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@dataclass\n",
|
||||
"class Message:\n",
|
||||
" content: Any\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class Termination:\n",
|
||||
" reason: str"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We code our agent to publish a termination message when it decides it is time to terminate."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@default_subscription\n",
|
||||
"class AnAgent(RoutedAgent):\n",
|
||||
" def __init__(self) -> None:\n",
|
||||
" super().__init__(\"MyAgent\")\n",
|
||||
" self.received = 0\n",
|
||||
"\n",
|
||||
" @message_handler\n",
|
||||
" async def on_new_message(self, message: Message, ctx: MessageContext) -> None:\n",
|
||||
" self.received += 1\n",
|
||||
" if self.received > 3:\n",
|
||||
" await self.publish_message(Termination(reason=\"Reached maximum number of messages\"), DefaultTopicId())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Next, we create an InterventionHandler that will detect the termination message and act on it. This one hooks into publishes and when it encounters `Termination` it alters its internal state to indicate that termination has been requested."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class TerminationHandler(DefaultInterventionHandler):\n",
|
||||
" def __init__(self) -> None:\n",
|
||||
" self._termination_value: Termination | None = None\n",
|
||||
"\n",
|
||||
" async def on_publish(self, message: Any, *, sender: AgentId | None) -> Any:\n",
|
||||
" if isinstance(message, Termination):\n",
|
||||
" self._termination_value = message\n",
|
||||
" return message\n",
|
||||
"\n",
|
||||
" @property\n",
|
||||
" def termination_value(self) -> Termination | None:\n",
|
||||
" return self._termination_value\n",
|
||||
"\n",
|
||||
" @property\n",
|
||||
" def has_terminated(self) -> bool:\n",
|
||||
" return self._termination_value is not None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Finally, we add this handler to the runtime and use it to detect termination and stop the runtime when the termination message is received."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Termination(reason='Reached maximum number of messages')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"termination_handler = TerminationHandler()\n",
|
||||
"runtime = SingleThreadedAgentRuntime(intervention_handlers=[termination_handler])\n",
|
||||
"\n",
|
||||
"await AnAgent.register(runtime, \"my_agent\", AnAgent)\n",
|
||||
"\n",
|
||||
"runtime.start()\n",
|
||||
"\n",
|
||||
"# Publish more than 3 messages to trigger termination.\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"\n",
|
||||
"# Wait for termination.\n",
|
||||
"await runtime.stop_when(lambda: termination_handler.has_terminated)\n",
|
||||
"\n",
|
||||
"print(termination_handler.termination_value)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Termination using Intervention Handler\n",
|
||||
"\n",
|
||||
"```{note}\n",
|
||||
"This method is valid when using {py:class}`~autogen_core.SingleThreadedAgentRuntime`.\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"There are many different ways to handle termination in `autogen_core`. Ultimately, the goal is to detect that the runtime no longer needs to be executed and you can proceed to finalization tasks. One way to do this is to use an {py:class}`autogen_core.base.intervention.InterventionHandler` to detect a termination message and then act on it."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from dataclasses import dataclass\n",
|
||||
"from typing import Any\n",
|
||||
"\n",
|
||||
"from autogen_core import (\n",
|
||||
" AgentId,\n",
|
||||
" DefaultTopicId,\n",
|
||||
" MessageContext,\n",
|
||||
" RoutedAgent,\n",
|
||||
" SingleThreadedAgentRuntime,\n",
|
||||
" default_subscription,\n",
|
||||
" message_handler,\n",
|
||||
")\n",
|
||||
"from autogen_core.base.intervention import DefaultInterventionHandler"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"First, we define a dataclass for regular message and message that will be used to signal termination."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@dataclass\n",
|
||||
"class Message:\n",
|
||||
" content: Any\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class Termination:\n",
|
||||
" reason: str"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We code our agent to publish a termination message when it decides it is time to terminate."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@default_subscription\n",
|
||||
"class AnAgent(RoutedAgent):\n",
|
||||
" def __init__(self) -> None:\n",
|
||||
" super().__init__(\"MyAgent\")\n",
|
||||
" self.received = 0\n",
|
||||
"\n",
|
||||
" @message_handler\n",
|
||||
" async def on_new_message(self, message: Message, ctx: MessageContext) -> None:\n",
|
||||
" self.received += 1\n",
|
||||
" if self.received > 3:\n",
|
||||
" await self.publish_message(Termination(reason=\"Reached maximum number of messages\"), DefaultTopicId())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Next, we create an InterventionHandler that will detect the termination message and act on it. This one hooks into publishes and when it encounters `Termination` it alters its internal state to indicate that termination has been requested."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class TerminationHandler(DefaultInterventionHandler):\n",
|
||||
" def __init__(self) -> None:\n",
|
||||
" self._termination_value: Termination | None = None\n",
|
||||
"\n",
|
||||
" async def on_publish(self, message: Any, *, sender: AgentId | None) -> Any:\n",
|
||||
" if isinstance(message, Termination):\n",
|
||||
" self._termination_value = message\n",
|
||||
" return message\n",
|
||||
"\n",
|
||||
" @property\n",
|
||||
" def termination_value(self) -> Termination | None:\n",
|
||||
" return self._termination_value\n",
|
||||
"\n",
|
||||
" @property\n",
|
||||
" def has_terminated(self) -> bool:\n",
|
||||
" return self._termination_value is not None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Finally, we add this handler to the runtime and use it to detect termination and stop the runtime when the termination message is received."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Termination(reason='Reached maximum number of messages')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"termination_handler = TerminationHandler()\n",
|
||||
"runtime = SingleThreadedAgentRuntime(intervention_handlers=[termination_handler])\n",
|
||||
"\n",
|
||||
"await AnAgent.register(runtime, \"my_agent\", AnAgent)\n",
|
||||
"\n",
|
||||
"runtime.start()\n",
|
||||
"\n",
|
||||
"# Publish more than 3 messages to trigger termination.\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"await runtime.publish_message(Message(\"hello\"), DefaultTopicId())\n",
|
||||
"\n",
|
||||
"# Wait for termination.\n",
|
||||
"await runtime.stop_when(lambda: termination_handler.has_terminated)\n",
|
||||
"\n",
|
||||
"print(termination_handler.termination_value)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
# API Layers
|
||||
|
||||
The API consists of the following layers:
|
||||
|
||||
- {py:mod}`autogen_core.base`
|
||||
- {py:mod}`autogen_core.application`
|
||||
- {py:mod}`autogen_core.components`
|
||||
|
||||
The following diagram shows the relationship between the layers.
|
||||
|
||||

|
||||
|
||||
The {py:mod}`autogen_core.base` layer defines the
|
||||
core interfaces and base classes for agents, messages, and runtime.
|
||||
This layer is the foundation of the framework and is used by the other layers.
|
||||
|
||||
The {py:mod}`autogen_core.application` layer provides concrete implementations of
|
||||
runtime and utilities like logging for building multi-agent applications.
|
||||
|
||||
The {py:mod}`autogen_core.components` layer provides reusable components for building
|
||||
AI agents, including type-routed agents, AI model clients, tools for AI models,
|
||||
code execution sandboxes, and memory stores.
|
||||
|
||||
The layers are loosely coupled and can be used independently. For example,
|
||||
you can swap out the runtime in the {py:mod}`autogen_core.application` layer with your own
|
||||
runtime implementation.
|
||||
You can also skip the components in the {py:mod}`autogen_core.components` layer and
|
||||
build your own components.
|
||||
@ -4,7 +4,7 @@ At the foundation level, the framework provides a _runtime environment_, which f
|
||||
communication between agents, manages their identities and lifecycles,
|
||||
and enforce security and privacy boundaries.
|
||||
|
||||
It supports two types of runtime environment: *standalone* and *distributed*.
|
||||
It supports two types of runtime environment: _standalone_ and _distributed_.
|
||||
Both types provide a common set of APIs for building multi-agent applications,
|
||||
so you can switch between them without changing your agent implementation.
|
||||
Each type can also have multiple implementations.
|
||||
@ -13,7 +13,7 @@ Each type can also have multiple implementations.
|
||||
|
||||
Standalone runtime is suitable for single-process applications where all agents
|
||||
are implemented in the same programming language and running in the same process.
|
||||
In the Python API, an example of standalone runtime is the {py:class}`~autogen_core.application.SingleThreadedAgentRuntime`.
|
||||
In the Python API, an example of standalone runtime is the {py:class}`~autogen_core.SingleThreadedAgentRuntime`.
|
||||
|
||||
The following diagram shows the standalone runtime in the framework.
|
||||
|
||||
@ -44,4 +44,3 @@ They advertise to the host servicer the agents they run and manage the agents' l
|
||||
|
||||
Agents work the same way as in the standalone runtime so that developers can
|
||||
switch between the two runtime types with no change to their agent implementation.
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ and the system architecture.
|
||||
|
||||
agent-and-multi-agent-application
|
||||
architecture
|
||||
api-layers
|
||||
application-stack
|
||||
agent-identity-and-lifecycle
|
||||
topic-and-subscription
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 100 KiB |
File diff suppressed because one or more lines are too long
@ -26,7 +26,7 @@
|
||||
"an agent runtime provides the necessary infrastructure to facilitate communication\n",
|
||||
"between agents, manage agent lifecycles, enforce security boundaries, and support monitoring and\n",
|
||||
"debugging.\n",
|
||||
"For local development, developers can use {py:class}`~autogen_core.application.SingleThreadedAgentRuntime`,\n",
|
||||
"For local development, developers can use {py:class}`~autogen_core.SingleThreadedAgentRuntime`,\n",
|
||||
"which can be embedded in a Python application.\n",
|
||||
"\n",
|
||||
"```{note}\n",
|
||||
@ -111,7 +111,7 @@
|
||||
"```\n",
|
||||
"\n",
|
||||
"To register an agent type with the \n",
|
||||
"{py:class}`~autogen_core.application.SingleThreadedAgentRuntime`,\n",
|
||||
"{py:class}`~autogen_core.SingleThreadedAgentRuntime`,\n",
|
||||
"the following code can be used:"
|
||||
]
|
||||
},
|
||||
@ -187,7 +187,7 @@
|
||||
"The above code snippet uses `runtime.start()` to start a background task\n",
|
||||
"to process and deliver messages to recepients' message handlers.\n",
|
||||
"This is a feature of the\n",
|
||||
"local embedded runtime {py:class}`~autogen_core.application.SingleThreadedAgentRuntime`.\n",
|
||||
"local embedded runtime {py:class}`~autogen_core.SingleThreadedAgentRuntime`.\n",
|
||||
"\n",
|
||||
"To stop the background task immediately, use the `stop()` method:"
|
||||
]
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now we can set up the worker agent runtimes.\n",
|
||||
"We use {py:class}`~autogen_core.application.GrpcWorkerAgentRuntime`.\n",
|
||||
"We use {py:class}`~autogen_ext.runtimes.grpc.GrpcWorkerAgentRuntime`.\n",
|
||||
"We set up two worker runtimes. Each runtime hosts one agent.\n",
|
||||
"All agents publish and subscribe to the default topic, so they can see all\n",
|
||||
"messages being published.\n",
|
||||
|
||||
@ -5,11 +5,11 @@ AutoGen uses Python's built-in [`logging`](https://docs.python.org/3/library/log
|
||||
There are two kinds of logging:
|
||||
|
||||
- **Trace logging**: This is used for debugging and is human readable messages to indicate what is going on. This is intended for a developer to understand what is happening in the code. The content and format of these logs should not be depended on by other systems.
|
||||
- Name: {py:attr}`~autogen_core.application.logging.TRACE_LOGGER_NAME`.
|
||||
- Name: {py:attr}`~autogen_core.TRACE_LOGGER_NAME`.
|
||||
- **Structured logging**: This logger emits structured events that can be consumed by other systems. The content and format of these logs can be depended on by other systems.
|
||||
- Name: {py:attr}`~autogen_core.application.logging.EVENT_LOGGER_NAME`.
|
||||
- See the module {py:mod}`autogen_core.application.logging.events` to see the available events.
|
||||
- {py:attr}`~autogen_core.application.logging.ROOT_LOGGER` can be used to enable or disable all logs.
|
||||
- Name: {py:attr}`~autogen_core.EVENT_LOGGER_NAME`.
|
||||
- See the module {py:mod}`autogen_core.logging` to see the available events.
|
||||
- {py:attr}`~autogen_core.ROOT_LOGGER_NAME` can be used to enable or disable all logs.
|
||||
|
||||
## Enabling logging output
|
||||
|
||||
@ -18,7 +18,7 @@ To enable trace logging, you can use the following code:
|
||||
```python
|
||||
import logging
|
||||
|
||||
from autogen_core.application.logging import TRACE_LOGGER_NAME
|
||||
from autogen_core import TRACE_LOGGER_NAME
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logger = logging.getLogger(TRACE_LOGGER_NAME)
|
||||
@ -62,7 +62,6 @@ my_handler = MyHandler()
|
||||
logger.handlers = [my_handler]
|
||||
```
|
||||
|
||||
|
||||
## Emitting logs
|
||||
|
||||
These two names are the root loggers for these types. Code that emits logs should use a child logger of these loggers. For example, if you are writing a module `my_module` and you want to emit trace logs, you should use the logger named:
|
||||
@ -70,7 +69,7 @@ These two names are the root loggers for these types. Code that emits logs shoul
|
||||
```python
|
||||
import logging
|
||||
|
||||
from autogen_core.application.logging import TRACE_LOGGER_NAME
|
||||
from autogen_core import TRACE_LOGGER_NAME
|
||||
logger = logging.getLogger(f"{TRACE_LOGGER_NAME}.my_module")
|
||||
```
|
||||
|
||||
@ -90,7 +89,7 @@ class MyEvent:
|
||||
Then it could be emitted in code like this:
|
||||
|
||||
```python
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
|
||||
logger = logging.getLogger(EVENT_LOGGER_NAME + ".my_module")
|
||||
logger.info(MyEvent("timestamp", "message"))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -2,8 +2,7 @@ import asyncio
|
||||
import logging
|
||||
|
||||
from _semantic_router_components import FinalResult, TerminationMessage, UserProxyMessage, WorkerAgentMessage
|
||||
from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handler
|
||||
from autogen_core.application.logging import TRACE_LOGGER_NAME
|
||||
from autogen_core import TRACE_LOGGER_NAME, DefaultTopicId, MessageContext, RoutedAgent, message_handler
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(f"{TRACE_LOGGER_NAME}.workers")
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import logging
|
||||
|
||||
from _semantic_router_components import AgentRegistryBase, IntentClassifierBase, TerminationMessage, UserProxyMessage
|
||||
from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler
|
||||
from autogen_core.application.logging import TRACE_LOGGER_NAME
|
||||
from autogen_core import (
|
||||
TRACE_LOGGER_NAME,
|
||||
DefaultTopicId,
|
||||
MessageContext,
|
||||
RoutedAgent,
|
||||
default_subscription,
|
||||
message_handler,
|
||||
)
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logger = logging.getLogger(f"{TRACE_LOGGER_NAME}.semantic_router")
|
||||
|
||||
@ -17,7 +17,8 @@ class LLMCallEvent:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from autogen_core.application.logging import LLMCallEvent, EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
from autogen_core.logging import LLMCallEvent
|
||||
|
||||
logger = logging.getLogger(EVENT_LOGGER_NAME)
|
||||
logger.info(LLMCallEvent(prompt_tokens=10, completion_tokens=20))
|
||||
|
||||
@ -26,9 +26,8 @@ import PIL.Image
|
||||
from autogen_agentchat.agents import BaseChatAgent
|
||||
from autogen_agentchat.base import Response
|
||||
from autogen_agentchat.messages import ChatMessage, MultiModalMessage, TextMessage
|
||||
from autogen_core import CancellationToken, FunctionCall
|
||||
from autogen_core import EVENT_LOGGER_NAME, CancellationToken, FunctionCall
|
||||
from autogen_core import Image as AGImage
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core.components.models import (
|
||||
AssistantMessage,
|
||||
ChatCompletionClient,
|
||||
|
||||
@ -3,8 +3,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Union
|
||||
|
||||
from autogen_core import CancellationToken
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, CancellationToken
|
||||
from autogen_core.components.models import (
|
||||
ChatCompletionClient,
|
||||
CreateResult,
|
||||
|
||||
@ -5,8 +5,7 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.code_executor import CodeBlock
|
||||
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
|
||||
from autogen_magentic_one.agents.coder import Coder, Executor
|
||||
|
||||
@ -7,8 +7,7 @@ round-robin orchestrator agent. The code snippets are executed inside a docker c
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.code_executor import CodeBlock
|
||||
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
|
||||
from autogen_magentic_one.agents.coder import Coder, Executor
|
||||
|
||||
@ -5,8 +5,7 @@ to write input or perform actions, orchestrated by an round-robin orchestrator a
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_magentic_one.agents.file_surfer import FileSurfer
|
||||
from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
|
||||
from autogen_magentic_one.agents.user_proxy import UserProxy
|
||||
|
||||
@ -7,8 +7,7 @@ The code snippets are not executed in this example."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
|
||||
# from typing import Any, Dict, List, Tuple, Union
|
||||
from autogen_magentic_one.agents.coder import Coder
|
||||
|
||||
@ -7,8 +7,7 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
||||
from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfer
|
||||
from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
|
||||
from autogen_magentic_one.agents.user_proxy import UserProxy
|
||||
|
||||
@ -7,11 +7,11 @@ import json
|
||||
from dataclasses import asdict
|
||||
|
||||
from autogen_core import SingleThreadedAgentRuntime
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME
|
||||
from autogen_core import AgentId, AgentProxy
|
||||
from autogen_core import DefaultTopicId
|
||||
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
|
||||
from autogen_ext.code_executor.docker_executor import DockerCommandLineCodeExecutor
|
||||
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
|
||||
from autogen_core.code_executor import CodeBlock
|
||||
from autogen_magentic_one.agents.coder import Coder, Executor
|
||||
from autogen_magentic_one.agents.file_surfer import FileSurfer
|
||||
|
||||
@ -2,8 +2,7 @@ import asyncio
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from autogen_core import MessageContext, RoutedAgent, message_handler
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, MessageContext, RoutedAgent, message_handler
|
||||
|
||||
from autogen_magentic_one.messages import (
|
||||
AgentEvent,
|
||||
|
||||
@ -2,8 +2,7 @@ import logging
|
||||
import time
|
||||
from typing import List, Optional
|
||||
|
||||
from autogen_core import AgentProxy, CancellationToken, MessageContext
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core import EVENT_LOGGER_NAME, AgentProxy, CancellationToken, MessageContext
|
||||
from autogen_core.components.models import AssistantMessage, LLMMessage, UserMessage
|
||||
|
||||
from ..messages import BroadcastMessage, OrchestrationEvent, RequestReplyMessage, ResetMessage
|
||||
|
||||
@ -12,9 +12,8 @@ from typing import Any, BinaryIO, Dict, List, Optional, Tuple, Union, cast # An
|
||||
from urllib.parse import quote_plus # parse_qs, quote, unquote, urlparse, urlunparse
|
||||
|
||||
import aiofiles
|
||||
from autogen_core import CancellationToken, FunctionCall, default_subscription
|
||||
from autogen_core import EVENT_LOGGER_NAME, CancellationToken, FunctionCall, default_subscription
|
||||
from autogen_core import Image as AGImage
|
||||
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
||||
from autogen_core.components.models import (
|
||||
AssistantMessage,
|
||||
ChatCompletionClient,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user