Skip to content

Commit

Permalink
Move incoming message agent up to Web Agent so it can be used to respond
Browse files Browse the repository at this point in the history
  • Loading branch information
dkolas committed Jun 1, 2023
1 parent cb12102 commit 3429685
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class TelegramBotConfig(Config):
class TelegramAgentService(SteamshipWidgetAgentService, ABC):
config: TelegramBotConfig
telegram_transport: TelegramTransport
incoming_message_agent: Agent

@classmethod
def config_cls(cls) -> Type[Config]:
Expand Down
8 changes: 5 additions & 3 deletions src/steamship/experimental/package_starters/web_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Optional

from steamship import Block
from steamship.agents.schema import AgentContext
from steamship.agents.schema import Agent, AgentContext
from steamship.agents.service.agent_service import AgentService
from steamship.experimental.transports.steamship_widget import SteamshipWidgetTransport
from steamship.invocable import post
Expand All @@ -23,10 +23,12 @@ def response_for_exception(e: Optional[Exception], chat_id: Optional[str] = None

class SteamshipWidgetAgentService(AgentService, ABC):
steamship_widget_transport: SteamshipWidgetTransport
incoming_message_agent: Agent

def __init__(self, **kwargs):
def __init__(self, incoming_message_agent: Agent, **kwargs):
super().__init__(**kwargs)
self.steamship_widget_transport = SteamshipWidgetTransport(client=self.client)
self.incoming_message_agent = incoming_message_agent

@post("answer", public=True)
def answer(self, **payload) -> List[Block]:
Expand All @@ -37,7 +39,7 @@ def answer(self, **payload) -> List[Block]:
)
context.chat_history.append_user_message(text=incoming_message.text)
try:
response = self.create_response(context)
response = self.run_agent(self.incoming_message_agent, context)
except Exception as e:
response = response_for_exception(e, chat_id=incoming_message.chat_id)

Expand Down

0 comments on commit 3429685

Please sign in to comment.