GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing doc.agentscope.io — Concurrent Agents - AgentScope Note Go to the end to download the full example code. Concurrent Agents¶With the help of asynchronous programming, the concurrent agents can be executed by A simple example is shown below, where two agents are created and executed concurrently. Agent 1 started at 08:40:13.327 Agent 2 started at 08:40:13.328 Agent 1 finished at 08:40:16.331 Agent 2 finished at 08:40:16.331 import asyncio from datetime import datetime from typing import Any from agentscope.agent import AgentBase class ExampleAgent(AgentBase): """The example agent for concurrent execution.""" def __init__(self, name: str) -> None: """Initialize the agent with its name.""" super().__init__() self.name = name async def reply(self, *args: Any, **kwargs: Any) -> None: """Reply to the message.""" start_time = datetime.now().strftime("%H:%M:%S.%f")[:-3] print(f"{self.name} started at {start_time}") await asyncio.sleep(3) # Simulate a long-running task end_time = datetime.now().strftime("%H:%M:%S.%f")[:-3] print(f"{self.name} finished at {end_time}") async def run_concurrent_agents() -> None: """Run the concurrent agents.""" agent1 = ExampleAgent("Agent 1") agent2 = ExampleAgent("Agent 2") await asyncio.gather(agent1(), agent2()) asyncio.run(run_concurrent_agents()) Total running time of the script: (0 minutes 3.005 seconds) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |