Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(scripts): assign a list of TextBlock to the content instead of a string (#1629)
qbc595d2a513af2
diff --git a/scripts/model_examples/anthropic_call.py b/scripts/model_examples/anthropic_call.pyindex db18c2e3d..1e4da66fc 100644--- a/scripts/model_examples/anthropic_call.py+++ b/scripts/model_examples/anthropic_call.py@@ -7,6 +7,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -38,7 +39,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -86,7 +87,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Shanghai?",+ content=[TextBlock(text="What is the weather in Shanghai?")],role="user",),]diff --git a/scripts/model_examples/anthropic_multiagent.py b/scripts/model_examples/anthropic_multiagent.pyindex 8c0901bcc..b28009cb7 100644--- a/scripts/model_examples/anthropic_multiagent.py+++ b/scripts/model_examples/anthropic_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import AnthropicMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import AnthropicChatModelfrom agentscope.credential import AnthropicCredential@@ -38,32 +38,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/anthropic_multiagent_multimodal.py b/scripts/model_examples/anthropic_multiagent_multimodal.pyindex a4d79569d..add7040d3 100644--- a/scripts/model_examples/anthropic_multiagent_multimodal.py+++ b/scripts/model_examples/anthropic_multiagent_multimodal.py@@ -42,11 +42,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -61,18 +65,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/dashscope_call.py b/scripts/model_examples/dashscope_call.pyindex ac77abbda..7791e8dac 100644--- a/scripts/model_examples/dashscope_call.py+++ b/scripts/model_examples/dashscope_call.py@@ -10,6 +10,7 @@ from agentscope.message import (ToolCallBlock,ToolResultBlock,ToolResultState,+ TextBlock,)from agentscope.model import DashScopeChatModelfrom agentscope.credential import DashScopeCredential@@ -35,7 +36,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -83,7 +84,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Beijing?",+ content=[TextBlock(text="What is the weather in Beijing?")],role="user",),]diff --git a/scripts/model_examples/dashscope_multiagent.py b/scripts/model_examples/dashscope_multiagent.pyindex c2d5a19fa..8a08a33d8 100644--- a/scripts/model_examples/dashscope_multiagent.py+++ b/scripts/model_examples/dashscope_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import DashScopeMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import DashScopeChatModelfrom agentscope.credential import DashScopeCredential@@ -37,32 +37,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/dashscope_multiagent_multimodal.py b/scripts/model_examples/dashscope_multiagent_multimodal.pyindex b9189b6a1..76f1b4976 100644--- a/scripts/model_examples/dashscope_multiagent_multimodal.py+++ b/scripts/model_examples/dashscope_multiagent_multimodal.py@@ -41,11 +41,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -60,18 +64,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/deepseek_call.py b/scripts/model_examples/deepseek_call.pyindex a4ecda5b9..a96545d9c 100644--- a/scripts/model_examples/deepseek_call.py+++ b/scripts/model_examples/deepseek_call.py@@ -12,6 +12,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -39,7 +40,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -87,7 +88,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Shenzhen?",+ content=[TextBlock(text="What is the weather in Shenzhen?")],role="user",),]diff --git a/scripts/model_examples/deepseek_multiagent.py b/scripts/model_examples/deepseek_multiagent.pyindex 28a02343a..e4f992d5e 100644--- a/scripts/model_examples/deepseek_multiagent.py+++ b/scripts/model_examples/deepseek_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import DeepSeekMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import DeepSeekChatModelfrom agentscope.credential import DeepSeekCredential@@ -38,32 +38,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/gemini_call.py b/scripts/model_examples/gemini_call.pyindex 611c69cf6..9ac5f95ef 100644--- a/scripts/model_examples/gemini_call.py+++ b/scripts/model_examples/gemini_call.py@@ -7,6 +7,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -38,7 +39,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -86,7 +87,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Guangzhou?",+ content=[TextBlock(text="What is the weather in Guangzhou?")],role="user",),]diff --git a/scripts/model_examples/gemini_multiagent.py b/scripts/model_examples/gemini_multiagent.pyindex d99777522..74d5e4ab2 100644--- a/scripts/model_examples/gemini_multiagent.py+++ b/scripts/model_examples/gemini_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import GeminiMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import GeminiChatModelfrom agentscope.credential import GeminiCredential@@ -38,32 +38,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/gemini_multiagent_multimodal.py b/scripts/model_examples/gemini_multiagent_multimodal.pyindex 4ce040a7e..a9867a8ec 100644--- a/scripts/model_examples/gemini_multiagent_multimodal.py+++ b/scripts/model_examples/gemini_multiagent_multimodal.py@@ -36,11 +36,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -55,18 +59,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/moonshot_call.py b/scripts/model_examples/moonshot_call.pyindex 396edf5e8..a77e91267 100644--- a/scripts/model_examples/moonshot_call.py+++ b/scripts/model_examples/moonshot_call.py@@ -7,6 +7,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -34,7 +35,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -76,7 +77,11 @@ async def example_tool_call() -> None:)msgs = [- Msg(name="user", content="What is the weather in Xi'an?", role="user"),+ Msg(+ name="user",+ content=[TextBlock(text="What is the weather in Xi'an?")],+ role="user",+ ),]# First call: model decides to call a tooldiff --git a/scripts/model_examples/moonshot_multiagent.py b/scripts/model_examples/moonshot_multiagent.pyindex 502818805..e3929ea1e 100644--- a/scripts/model_examples/moonshot_multiagent.py+++ b/scripts/model_examples/moonshot_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import MoonshotMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import MoonshotChatModelfrom agentscope.credential import MoonshotCredential@@ -37,32 +37,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/moonshot_multiagent_multimodal.py b/scripts/model_examples/moonshot_multiagent_multimodal.pyindex 88fa7534b..86c1f5655 100644--- a/scripts/model_examples/moonshot_multiagent_multimodal.py+++ b/scripts/model_examples/moonshot_multiagent_multimodal.py@@ -37,11 +37,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -56,18 +60,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/ollama_call.py b/scripts/model_examples/ollama_call.pyindex 56c622192..6a0519e85 100644--- a/scripts/model_examples/ollama_call.py+++ b/scripts/model_examples/ollama_call.py@@ -13,6 +13,7 @@ import jsonfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -41,7 +42,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -86,7 +87,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Nanjing?",+ content=[TextBlock(text="What is the weather in Nanjing?")],role="user",),]diff --git a/scripts/model_examples/ollama_multiagent.py b/scripts/model_examples/ollama_multiagent.pyindex 636352420..2af53a5d1 100644--- a/scripts/model_examples/ollama_multiagent.py+++ b/scripts/model_examples/ollama_multiagent.py@@ -9,7 +9,7 @@ import asynciofrom _utils import stream_and_collectfrom agentscope.formatter import OllamaMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import OllamaChatModel@@ -32,32 +32,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/ollama_multiagent_multimodal.py b/scripts/model_examples/ollama_multiagent_multimodal.pyindex b55f0aba6..97c4f5754 100644--- a/scripts/model_examples/ollama_multiagent_multimodal.py+++ b/scripts/model_examples/ollama_multiagent_multimodal.py@@ -38,11 +38,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -57,18 +61,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/openai_chat_call.py b/scripts/model_examples/openai_chat_call.pyindex 04316c7ea..6d2c9a0d4 100644--- a/scripts/model_examples/openai_chat_call.py+++ b/scripts/model_examples/openai_chat_call.py@@ -7,6 +7,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -37,7 +38,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -84,7 +85,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Chengdu?",+ content=[TextBlock(text="What is the weather in Chengdu?")],role="user",),]diff --git a/scripts/model_examples/openai_chat_multiagent.py b/scripts/model_examples/openai_chat_multiagent.pyindex 4cc27ced1..babd3ade6 100644--- a/scripts/model_examples/openai_chat_multiagent.py+++ b/scripts/model_examples/openai_chat_multiagent.py@@ -10,7 +10,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import OpenAIMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import OpenAIChatModelfrom agentscope.credential import OpenAICredential@@ -37,32 +37,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/openai_chat_multiagent_multimodal.py b/scripts/model_examples/openai_chat_multiagent_multimodal.pyindex 8f58ea2ca..761f6b015 100644--- a/scripts/model_examples/openai_chat_multiagent_multimodal.py+++ b/scripts/model_examples/openai_chat_multiagent_multimodal.py@@ -37,11 +37,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -56,18 +60,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/openai_response_call.py b/scripts/model_examples/openai_response_call.pyindex db120bbee..947522e35 100644--- a/scripts/model_examples/openai_response_call.py+++ b/scripts/model_examples/openai_response_call.py@@ -12,6 +12,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -40,7 +41,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -85,7 +86,7 @@ async def example_tool_call() -> None:msgs = [Msg(name="user",- content="What is the weather in Hangzhou?",+ content=[TextBlock(text="What is the weather in Hangzhou?")],role="user",),]diff --git a/scripts/model_examples/openai_response_multiagent.py b/scripts/model_examples/openai_response_multiagent.pyindex da1b4590a..94f7de72f 100644--- a/scripts/model_examples/openai_response_multiagent.py+++ b/scripts/model_examples/openai_response_multiagent.py@@ -11,7 +11,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import OpenAIResponseMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import OpenAIResponseModelfrom agentscope.credential import OpenAICredential@@ -39,32 +39,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/openai_response_multiagent_multimodal.py b/scripts/model_examples/openai_response_multiagent_multimodal.pyindex f6b909393..3754145d0 100644--- a/scripts/model_examples/openai_response_multiagent_multimodal.py+++ b/scripts/model_examples/openai_response_multiagent_multimodal.py@@ -37,11 +37,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -56,18 +60,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/xai_call.py b/scripts/model_examples/xai_call.pyindex 1240022fe..e99ccdbd3 100644--- a/scripts/model_examples/xai_call.py+++ b/scripts/model_examples/xai_call.py@@ -12,6 +12,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.message import (Msg,+ TextBlock,ToolCallBlock,ToolResultBlock,ToolResultState,@@ -40,7 +41,7 @@ async def example_simple_call() -> None:msgs = [Msg(name="user",- content="What is 1 + 1? Answer briefly.",+ content=[TextBlock(text="What is 1 + 1? Answer briefly.")],role="user",),]@@ -85,7 +86,11 @@ async def example_tool_call() -> None:)msgs = [- Msg(name="user", content="What is the weather in Wuhan?", role="user"),+ Msg(+ name="user",+ content=[TextBlock(text="What is the weather in Wuhan?")],+ role="user",+ ),]# First call: model decides to call a tooldiff --git a/scripts/model_examples/xai_multiagent.py b/scripts/model_examples/xai_multiagent.pyindex a6d80e4e1..a4573f4b7 100644--- a/scripts/model_examples/xai_multiagent.py+++ b/scripts/model_examples/xai_multiagent.py@@ -11,7 +11,7 @@ import osfrom _utils import stream_and_collectfrom agentscope.formatter import XAIMultiAgentFormatter-from agentscope.message import Msg+from agentscope.message import Msg, TextBlockfrom agentscope.model import XAIChatModelfrom agentscope.credential import XAICredential@@ -38,32 +38,57 @@ async def example_multiagent() -> None:msgs = [Msg(name="system",- content="You are a helpful moderator. Summarize the conversation.",+ content=[+ TextBlock(+ text="You are a helpful moderator. Summarize the "+ "conversation.",+ ),+ ],role="system",),Msg(name="alice",- content="Hi Bob! What do you think about the weather today?",+ content=[+ TextBlock(+ text="Hi Bob! What do you think about the weather today?",+ ),+ ],role="user",),Msg(name="bob",- content="It's quite sunny and warm, Alice. Perfect for a walk!",+ content=[+ TextBlock(+ text="It's quite sunny and warm, Alice. Perfect for a "+ "walk!",+ ),+ ],role="assistant",),Msg(name="alice",- content="Agreed! I might head to the park later.",+ content=[+ TextBlock(text="Agreed! I might head to the park later."),+ ],role="user",),Msg(name="bob",- content="Great idea. I'll join you if I finish work early.",+ content=[+ TextBlock(+ text="Great idea. I'll join you if I finish work early.",+ ),+ ],role="assistant",),Msg(name="moderator",- content="Please summarize the conversation above in one sentence.",+ content=[+ TextBlock(+ text="Please summarize the conversation above in one "+ "sentence.",+ ),+ ],role="user",),]diff --git a/scripts/model_examples/xai_multiagent_multimodal.py b/scripts/model_examples/xai_multiagent_multimodal.pyindex ae1678e8d..66bcd6004 100644--- a/scripts/model_examples/xai_multiagent_multimodal.py+++ b/scripts/model_examples/xai_multiagent_multimodal.py@@ -40,11 +40,15 @@ async def example_multiagent_image_url() -> None:msgs = [Msg(name="system",- content=(- "You are a helpful moderator in a group chat. "- "Summarize what the image shows and what the participants "- "said."- ),+ content=[+ TextBlock(+ text=(+ "You are a helpful moderator in a group chat. "+ "Summarize what the image shows and what the "+ "participants said."+ ),+ ),+ ],role="system",),Msg(@@ -59,18 +63,24 @@ async def example_multiagent_image_url() -> None:),Msg(name="bob",- content="Aww, that's adorable! Where was this taken?",+ content=[+ TextBlock(text="Aww, that's adorable! Where was this taken?"),+ ],role="assistant",),Msg(name="alice",- content="At the local park yesterday.",+ content=[TextBlock(text="At the local park yesterday.")],role="user",),Msg(name="moderator",- content="Please summarize the image content and the "- "conversation in one paragraph.",+ content=[+ TextBlock(+ text="Please summarize the image content and the "+ "conversation in one paragraph.",+ ),+ ],role="user",),]