Skip to content

Commit e919625

Browse files
committed
multiturnresponse for injecting assistant prefill
1 parent ca38042 commit e919625

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

asimov/graph/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ async def run_node(self, node_name: str) -> Dict[str, Any]:
708708
continue
709709

710710
return result
711+
except asyncio.CancelledError:
712+
raise
711713
except Exception as e:
712714
last_exception = e
713715

@@ -922,5 +924,6 @@ async def run_from_snapshot(self, snapshot_dir: pathlib.Path):
922924
task = pickle.load(f)
923925
await self._run_task(task)
924926

927+
925928
# Need to build after CompositeModule is defined
926929
AgentModule.model_rebuild()

asimov/services/inference_clients.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ class ChatMessage(AsimovBase):
6464
model_families: List[str] = Field(default_factory=list)
6565

6666

67+
class MultiTurnResponse:
68+
def __init__(self, first_response: str, others: list[ChatMessage]):
69+
self.first_response = first_response
70+
self.others = others
71+
72+
def __str__(self):
73+
return self.first_response
74+
75+
6776
class AnthropicRequest(AsimovBase):
6877
anthropic_version: str
6978
system: str
@@ -342,6 +351,20 @@ async def tool_chain(
342351
"content": content_blocks,
343352
}
344353
)
354+
if isinstance(result, MultiTurnResponse):
355+
for other in result.others:
356+
serialized_messages.append(
357+
{
358+
"role": other.role.value,
359+
"content": [
360+
{
361+
"type": "text",
362+
"text": other.content,
363+
}
364+
],
365+
}
366+
)
367+
345368
return serialized_messages
346369

347370

0 commit comments

Comments
 (0)