Skip to content

Commit ce50e86

Browse files
eobdouglas-reid
andauthored
Two minimum viable agents (#482)
These are two agents which appear in the Agent Guidebook. I was thinking it'd be good to make sure these are captured in the official codebase so that we could begin to write tests against them and then eventually find a way to import them **from this repo** into the website itself directly. --------- Co-authored-by: Douglas Reid <douglas-reid@users.noreply.github.com>
1 parent f934fdd commit ce50e86

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ fabric.properties
107107

108108
# Generated website
109109
docs/_build
110-
venv
110+
venv
111+
logs/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Minimum viable AgentService implementation.
2+
3+
This will result in an agent that effectively acts like ChatGPT.
4+
"""
5+
6+
from steamship.agents.functional import FunctionsBasedAgent
7+
from steamship.agents.llms.openai import ChatOpenAI
8+
from steamship.agents.service.agent_service import AgentService
9+
from steamship.utils.repl import AgentREPL
10+
11+
12+
class MyAssistant(AgentService):
13+
def __init__(self, **kwargs):
14+
super().__init__(**kwargs)
15+
self._agent = FunctionsBasedAgent(llm=ChatOpenAI(self.client), tools=[])
16+
17+
18+
if __name__ == "__main__":
19+
AgentREPL(
20+
MyAssistant,
21+
agent_package_config={},
22+
).run()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Minimum viable AgentService implementation with Web Widget & Telegram support.
2+
3+
This will result in an agent that acts like ChatGPT and can be communicated with on the Steamship website
4+
as well as over Telegram.
5+
"""
6+
from typing import Type
7+
8+
from pydantic import Field
9+
10+
from steamship.agents.examples.telegram_bot import TelegramBot
11+
from steamship.agents.functional import FunctionsBasedAgent
12+
from steamship.agents.llms.openai import ChatOpenAI
13+
from steamship.agents.mixins.transports.steamship_widget import SteamshipWidgetTransport
14+
from steamship.agents.mixins.transports.telegram import TelegramTransport, TelegramTransportConfig
15+
from steamship.agents.service.agent_service import AgentService
16+
from steamship.invocable import Config
17+
from steamship.utils.repl import AgentREPL
18+
19+
20+
class MyAssistant(AgentService):
21+
class MyAssistantConfig(Config):
22+
bot_token: str = Field(description="The secret token for your Telegram bot")
23+
24+
config: MyAssistantConfig
25+
26+
@classmethod
27+
def config_cls(cls) -> Type[Config]:
28+
return TelegramBot.TelegramBotConfig
29+
30+
def __init__(self, **kwargs):
31+
super().__init__(**kwargs)
32+
33+
self._agent = FunctionsBasedAgent(llm=ChatOpenAI(self.client), tools=[])
34+
35+
# This Mixin provides HTTP endpoints that connects this agent to a web client
36+
self.add_mixin(
37+
SteamshipWidgetTransport(client=self.client, agent_service=self, agent=self._agent)
38+
)
39+
# This Mixin provides support for Telegram bots
40+
self.add_mixin(
41+
TelegramTransport(
42+
client=self.client,
43+
config=TelegramTransportConfig(bot_token=self.config.bot_token),
44+
agent_service=self,
45+
agent=self._agent,
46+
)
47+
)
48+
49+
50+
if __name__ == "__main__":
51+
AgentREPL(
52+
MyAssistant,
53+
agent_package_config={"botToken": "not-a-real-token-for-local-testing"},
54+
).run()

0 commit comments

Comments
 (0)