Skip to content

Commit

Permalink
Fix issues in python core samples (#549)
Browse files Browse the repository at this point in the history
* fix issues

* remove sender from send_message call

* Fix agent type

---------

Co-authored-by: Aaron Gaetje <[email protected]>
Co-authored-by: Jack Gerrits <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent f3bb058 commit 4998ab5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def on_new_message(self, message: MessageType, ctx: MessageContext) -> Mes
async def main() -> None:
runtime = SingleThreadedAgentRuntime()
await runtime.register("inner", Inner)
await runtime.register("outer", lambda: Outer(AgentId("outer", AgentInstantiationContext.current_agent_id().key)))
await runtime.register("outer", lambda: Outer(AgentId("inner", AgentInstantiationContext.current_agent_id().key)))
outer = AgentId("outer", "default")

runtime.start()
Expand Down
20 changes: 11 additions & 9 deletions python/packages/autogen-core/samples/core/two_agents_pub_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import List

from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.base import AgentId
from autogen_core.base import AgentId, MessageContext
from autogen_core.components import DefaultSubscription, DefaultTopicId, RoutedAgent, message_handler
from autogen_core.components.models import (
AssistantMessage,
Expand All @@ -29,7 +29,6 @@

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from autogen_core.base import MessageContext
from common.utils import get_chat_completion_client_from_envs


Expand Down Expand Up @@ -71,10 +70,9 @@ async def handle_message(self, message: Message, ctx: MessageContext) -> None:
response = await self._model_client.create(self._system_messages + llm_messages)
assert isinstance(response.content, str)

if ctx.topic_id is not None:
await self.publish_message(
Message(content=response.content, source=self.metadata["type"]), topic_id=DefaultTopicId()
)
await self.publish_message(
Message(content=response.content, source=self.metadata["type"]), topic_id=DefaultTopicId()
)


async def main() -> None:
Expand All @@ -88,7 +86,9 @@ async def main() -> None:
description="Jack a comedian",
model_client=get_chat_completion_client_from_envs(model="gpt-4o-mini"),
system_messages=[
SystemMessage("You are a comedian likes to make jokes. " "When you are done talking, say 'TERMINATE'.")
SystemMessage(
"You are a comedian that likes to make jokes. " "After multiple turns, respond with 'TERMINATE'"
)
],
termination_word="TERMINATE",
),
Expand All @@ -100,7 +100,9 @@ async def main() -> None:
description="Cathy a poet",
model_client=get_chat_completion_client_from_envs(model="gpt-4o-mini"),
system_messages=[
SystemMessage("You are a poet likes to write poems. " "When you are done talking, say 'TERMINATE'.")
SystemMessage(
"You are a poet likes that to write poems. " "After multiple turns, respond with 'TERMINATE'"
)
],
termination_word="TERMINATE",
),
Expand All @@ -111,7 +113,7 @@ async def main() -> None:

# Send a message to Jack to start the conversation.
message = Message(content="Can you tell me something fun about SF?", source="User")
await runtime.send_message(message, AgentId("jack", "default"))
await runtime.send_message(message, AgentId("Jack", "default"))

# Process messages.
await runtime.stop_when_idle()
Expand Down

0 comments on commit 4998ab5

Please sign in to comment.