Skip to content

Commit

Permalink
Add AgentSpec.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed Dec 28, 2024
1 parent 6c02fba commit 024a6e0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions coagent/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,26 @@ class AgentSpec:

_runtime: Runtime | None = None

async def run(self, msg: RawMessage, timeout: float = 0.5) -> RawMessage:
self._assert_runtime()

addr = Address(name=self.name, id=uuid.uuid4().hex)
return await self._runtime.channel.publish(
addr, msg, request=True, timeout=timeout
)

async def run_stream(self, msg: RawMessage) -> AsyncIterator[RawMessage]:
if self._runtime is None:
raise ValueError(f"AgentSpec {self.name} is not registered to a runtime.")
self._assert_runtime()

addr = Address(name=self.name, id=uuid.uuid4().hex)
result = self._runtime.channel.publish_multi(addr, msg)
async for chunk in result:
yield chunk

def _assert_runtime(self) -> None:
if self._runtime is None:
raise ValueError(f"AgentSpec {self.name} is not registered to a runtime.")


class Runtime(abc.ABC):
async def __aenter__(self):
Expand Down

0 comments on commit 024a6e0

Please sign in to comment.