Skip to content

Commit eef91b0

Browse files
committed
Add support for DeepSeek-R1
1 parent 49c1081 commit eef91b0

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

coagent/agents/aswarm/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ async def run_and_stream(
234234
while len(history) - init_len < max_turns:
235235
message = {
236236
"content": "",
237+
"reasoning_content": "",
237238
# No `sender` param is supported by model
238239
# "sender": agent.name,
239240
"role": "assistant",
@@ -263,11 +264,16 @@ async def run_and_stream(
263264
delta = json.loads(chunk.choices[0].delta.json())
264265
if delta["role"] == "assistant":
265266
delta["sender"] = active_agent.name
266-
if delta["content"]:
267+
268+
delta_content = delta.get("content") or ""
269+
delta_reasoning_content = delta.get("reasoning_content") or ""
270+
if delta_content or delta_reasoning_content:
267271
yield ChatMessage(
268272
role=delta["role"] or "assistant",
269-
content=delta["content"],
273+
content=delta_content,
274+
reasoning_content=delta_reasoning_content,
270275
)
276+
271277
delta.pop("role", None)
272278
delta.pop("sender", None)
273279
merge_chunk(message, delta)

coagent/agents/chat_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async def _handle_history(
281281
context_variables=msg.extensions,
282282
)
283283
async for resp in response:
284-
if isinstance(resp, ChatMessage) and resp.content:
284+
if isinstance(resp, ChatMessage) and resp.has_content:
285285
yield resp
286286

287287
async def update_user_confirmed(self, history: ChatHistory) -> None:

coagent/agents/messages.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77

88

99
class ChatMessage(Message):
10-
role: str
11-
content: str
10+
role: str = Field(
11+
..., description="The role of the message. (e.g. `user`, `assistant`)"
12+
)
13+
content: str = Field(
14+
default="",
15+
description="The content of the message. For reasoning models, this is the content of the final answer.",
16+
)
17+
reasoning_content: str = Field(
18+
default="",
19+
description="The content of the CoT. Only available for reasoning models.",
20+
)
1221

1322
type: str = Field(default="", description="The type of the message. e.g. confirm")
1423
sender: str = Field(default="", description="The sending agent of the message.")
@@ -18,8 +27,13 @@ class ChatMessage(Message):
1827

1928
def __add__(self, other: ChatMessage) -> ChatMessage:
2029
self.content += other.content
30+
self.reasoning_content += other.reasoning_content
2131
return self
2232

33+
@property
34+
def has_content(self) -> bool:
35+
return bool(self.content or self.reasoning_content)
36+
2337
def model_dump(self, **kwargs) -> dict[str, Any]:
2438
return super().model_dump(include={"role", "content"}, **kwargs)
2539

poetry.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ httpx-sse = "0.4.0"
2929
blinker = "1.9.0"
3030
loguru = "0.7.3"
3131
jq = "1.8.0"
32-
litellm = "1.55.12"
32+
litellm = "1.60.4"
3333
mcp = "1.2.0"
3434

3535
[tool.pyright]

uv.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)