feat: Add synopisis core loop (#166)
Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
import json
|
||||
from attrs import define, asdict
|
||||
|
||||
|
||||
@@ -21,6 +22,10 @@ class Content:
|
||||
class Text(Content):
|
||||
text: str
|
||||
|
||||
@property
|
||||
def summary(self) -> str:
|
||||
return "content:text\n" + self.text
|
||||
|
||||
|
||||
@define
|
||||
class ToolUse(Content):
|
||||
@@ -30,9 +35,17 @@ class ToolUse(Content):
|
||||
is_error: bool = False
|
||||
error_message: Optional[str] = None
|
||||
|
||||
@property
|
||||
def summary(self) -> str:
|
||||
return f"content:tool_use:{self.name}\nparameters:{json.dumps(self.parameters)}"
|
||||
|
||||
|
||||
@define
|
||||
class ToolResult(Content):
|
||||
tool_use_id: str
|
||||
output: str
|
||||
is_error: bool = False
|
||||
|
||||
@property
|
||||
def summary(self) -> str:
|
||||
return f"content:tool_result:error={self.is_error}\noutput:{self.output}"
|
||||
|
||||
@@ -119,3 +119,7 @@ class Message:
|
||||
@classmethod
|
||||
def assistant(cls: type["Message"], text: str) -> "Message":
|
||||
return cls(role="assistant", content=[Text(text)])
|
||||
|
||||
@property
|
||||
def summary(self) -> str:
|
||||
return f"message:{self.role}\n" + "\n".join(content.summary for content in self.content)
|
||||
|
||||
Reference in New Issue
Block a user