Skip to content

Commit

Permalink
Rename TypeRoutedAgent to RoutedAgent; log on unhandled message. (#400)
Browse files Browse the repository at this point in the history
* Rename TypeRoutedAgent to RoutedAgent; log on unhandled message.

* format

* Deprecation warning

* add test for routed agent

* add TypeRoutedAgent import

* fix import
  • Loading branch information
ekzhu authored Aug 23, 2024
1 parent 4c964fa commit d7ae203
Show file tree
Hide file tree
Showing 44 changed files with 557 additions and 525 deletions.
6 changes: 3 additions & 3 deletions python/docs/src/cookbook/langgraph-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"from typing import Any, Callable, List, Literal\n",
"\n",
"from agnext.application import SingleThreadedAgentRuntime\n",
"from agnext.components import TypeRoutedAgent, message_handler\n",
"from agnext.components import RoutedAgent, message_handler\n",
"from agnext.core import AgentId, MessageContext\n",
"from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n",
"from langchain_core.messages import HumanMessage, SystemMessage\n",
Expand Down Expand Up @@ -107,7 +107,7 @@
"metadata": {},
"outputs": [],
"source": [
"class LangGraphToolUseAgent(TypeRoutedAgent):\n",
"class LangGraphToolUseAgent(RoutedAgent):\n",
" def __init__(self, description: str, model: ChatOpenAI, tools: List[Callable[..., Any]]) -> None: # pyright: ignore\n",
" super().__init__(description)\n",
" self._model = model.bind_tools(tools) # pyright: ignore\n",
Expand Down Expand Up @@ -297,4 +297,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
6 changes: 3 additions & 3 deletions python/docs/src/cookbook/llamaindex-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"from typing import List, Optional\n",
"\n",
"from agnext.application import SingleThreadedAgentRuntime\n",
"from agnext.components import TypeRoutedAgent, message_handler\n",
"from agnext.components import RoutedAgent, message_handler\n",
"from agnext.core import AgentId, MessageContext\n",
"from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n",
"from llama_index.core import Settings\n",
Expand Down Expand Up @@ -102,7 +102,7 @@
"metadata": {},
"outputs": [],
"source": [
"class LlamaIndexAgent(TypeRoutedAgent):\n",
"class LlamaIndexAgent(RoutedAgent):\n",
" def __init__(self, description: str, llama_index_agent: AgentRunner, memory: BaseMemory | None = None) -> None:\n",
" super().__init__(description)\n",
"\n",
Expand Down Expand Up @@ -530,4 +530,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
6 changes: 3 additions & 3 deletions python/docs/src/cookbook/openai-assistant-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@
"from typing import Any, Callable, List\n",
"\n",
"import aiofiles\n",
"from agnext.components import TypeRoutedAgent, message_handler\n",
"from agnext.components import RoutedAgent, message_handler\n",
"from agnext.core import AgentId, MessageContext\n",
"from openai import AsyncAssistantEventHandler, AsyncClient\n",
"from openai.types.beta.thread import ToolResources, ToolResourcesFileSearch\n",
"\n",
"\n",
"class OpenAIAssistantAgent(TypeRoutedAgent):\n",
"class OpenAIAssistantAgent(RoutedAgent):\n",
" \"\"\"An agent implementation that uses the OpenAI Assistant API to generate\n",
" responses.\n",
"\n",
Expand Down Expand Up @@ -839,4 +839,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
4 changes: 2 additions & 2 deletions python/docs/src/cookbook/termination-with-intervention.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from dataclasses import dataclass
from typing import Any

from agnext.application import SingleThreadedAgentRuntime
from agnext.components import TypeRoutedAgent, message_handler
from agnext.components import RoutedAgent, message_handler
from agnext.core import AgentId, CancellationToken
from agnext.core.intervention import DefaultInterventionHandler
```
Expand All @@ -28,7 +28,7 @@ class Termination:
We code our agent to publish a termination message when it decides it is time to terminate.

```python
class AnAgent(TypeRoutedAgent):
class AnAgent(RoutedAgent):
def __init__(self) -> None:
super().__init__("MyAgent")
self.received = 0
Expand Down
6 changes: 3 additions & 3 deletions python/docs/src/cookbook/type-routed-agent.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using Type Routed Agent

To make it easier to implement agents that respond to certain message types there is a base class called {py:class}`~agnext.components.TypeRoutedAgent`. This class provides a simple decorator pattern for associating message types with message handlers.
To make it easier to implement agents that respond to certain message types there is a base class called {py:class}`~agnext.components.RoutedAgent`. This class provides a simple decorator pattern for associating message types with message handlers.

The decorator {py:func}`agnext.components.message_handler` should be added to functions in the class that are intended to handle messages. These functions have a specific signature that needs to be followed for it to be recognized as a message handler.

Expand All @@ -25,7 +25,7 @@ One important thing to point out is that when an agent is constructed it must be
```python
from dataclasses import dataclass
from typing import List, Union
from agnext.components import TypeRoutedAgent, message_handler, Image
from agnext.components import RoutedAgent, message_handler, Image
from agnext.core import AgentRuntime, CancellationToken

@dataclass
Expand All @@ -43,7 +43,7 @@ class Reset:
pass


class MyAgent(TypeRoutedAgent):
class MyAgent(RoutedAgent):
def __init__(self):
super().__init__(description="I am a demo agent")
self._received_count = 0
Expand Down
Loading

0 comments on commit d7ae203

Please sign in to comment.