@@ -358,8 +358,9 @@ class NicknameGeneratorInput(BaseModel):
358358 Agent (
359359 model = await self .model (),
360360 system_prompt = (
361- "You are a helpful assistant that generates nicknames. A valid "
362- + "nickname consists of the provided name suffixed with '-zilla.'"
361+ "You are a helpful assistant that generates nicknames. "
362+ + "The nickname MUST be formatted as exactly '<name>-zilla' with a hyphen. "
363+ + "For example: Chris -> Chris-zilla, Alice -> Alice-zilla."
363364 ),
364365 service = self .service ,
365366 name = "NicknameGeneratorAgent" ,
@@ -406,15 +407,16 @@ async def test_middleware(
406407 first_response = await handler (request )
407408 second_response = await handler (request )
408409 assert isinstance (first_response .result , SubagentTextResult )
409- assert second_response == first_response
410+ assert isinstance ( second_response . result , SubagentTextResult )
410411 return second_response
411412
412413 async with (
413414 Agent (
414415 model = await self .model (),
415416 system_prompt = (
416- "You are a helpful assistant that generates nicknames. A valid "
417- + "nickname consists of the provided name suffixed with '-zilla.'"
417+ "You are a helpful assistant that generates nicknames. "
418+ + "The nickname MUST be formatted as exactly '<name>-zilla' with a hyphen. "
419+ + "For example: Chris -> Chris-zilla, Alice -> Alice-zilla."
418420 ),
419421 service = self .service ,
420422 name = "NicknameGeneratorAgent" ,
@@ -472,8 +474,9 @@ async def test_middleware(
472474 Agent (
473475 model = await self .model (),
474476 system_prompt = (
475- "You are a helpful assistant that generates nicknames. A valid "
476- + "nickname consists of the provided name suffixed with '-zilla.'"
477+ "You are a helpful assistant that generates nicknames. "
478+ + "The nickname MUST be formatted as exactly '<name>-zilla' with a hyphen. "
479+ + "For example: Chris -> Chris-zilla, Alice -> Alice-zilla."
477480 ),
478481 service = self .service ,
479482 name = "NicknameGeneratorAgent" ,
@@ -601,8 +604,9 @@ async def test_middleware(
601604 Agent (
602605 model = await self .model (),
603606 system_prompt = (
604- "You are a helpful assistant that generates nicknames. A valid "
605- + "nickname consists of the provided name suffixed with '-zilla.'"
607+ "You are a helpful assistant that generates nicknames. "
608+ + "The nickname MUST be formatted as exactly '<name>-zilla' with a hyphen. "
609+ + "For example: Chris -> Chris-zilla, Alice -> Alice-zilla."
606610 ),
607611 service = self .service ,
608612 name = "NicknameGeneratorAgent" ,
@@ -777,8 +781,9 @@ async def mutating_middleware(
777781 Agent (
778782 model = await self .model (),
779783 system_prompt = (
780- "You are a helpful assistant that generates nicknames. A valid "
781- "nickname consists of the provided name suffixed with '-zilla.'"
784+ "You are a helpful assistant that generates nicknames. "
785+ "The nickname MUST be formatted as exactly '<name>-zilla' with a hyphen. "
786+ "For example: Chris -> Chris-zilla, Alice -> Alice-zilla."
782787 ),
783788 service = self .service ,
784789 name = "NicknameGeneratorAgent" ,
@@ -796,7 +801,14 @@ async def mutating_middleware(
796801 result = await supervisor .invoke (
797802 [HumanMessage (content = "Generate a nickname for Bob" )]
798803 )
799- assert "Alice-zilla" in result .final_message .content
804+ # The middleware mutated the arg to "Alice", so the subagent must have
805+ # received "Alice" and returned "Alice-zilla". Check the subagent message.
806+ subagent_msg = next (
807+ (m for m in result .messages if isinstance (m , SubagentMessage )), None
808+ )
809+ assert subagent_msg is not None
810+ assert isinstance (subagent_msg .result , SubagentTextResult )
811+ assert "Alice-zilla" in subagent_msg .result .content
800812
801813 @pytest .mark .asyncio
802814 async def test_model_middleware_structured_output (self ) -> None :
0 commit comments