-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/refactor api #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a1f7780
ee78a65
edec412
c1f3fce
9ee5789
4fac2d5
be6bcdf
d61b186
dcc1cf1
4ee2dbb
600425d
2878335
5404820
9c98400
25f6f41
8c17ccd
f74d733
a4d0a1a
c6d95c9
b0a2a2d
fb493dd
7fad4c1
1b6b58c
3f4ceed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,7 +29,8 @@ | |||||||||||||||||||||||||
| from collections import defaultdict | ||||||||||||||||||||||||||
| from dataclasses import dataclass, field | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| from pulsing.actor import SystemConfig, create_actor_system | ||||||||||||||||||||||||||
| import pulsing as pul | ||||||||||||||||||||||||||
| from pulsing.actor import SystemConfig | ||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Unused import Note test
Import of 'SystemConfig' is not used.
Copilot AutofixAI 27 days ago In general, the way to fix an unused import is to delete the specific import line (or the unused symbol from a multi-symbol import) so that only actually used dependencies remain. This keeps the code cleaner, avoids unnecessary coupling, and silences the static analysis warning. For this file, the best fix without changing functionality is to remove the line that imports
Suggested changeset
1
benchmarks/queue_benchmark.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||
| from pulsing.queue import read_queue, write_queue | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -353,17 +354,18 @@ | |||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| port = args.port + rank | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| config = SystemConfig.with_addr(f"0.0.0.0:{port}") | ||||||||||||||||||||||||||
| addr = f"0.0.0.0:{port}" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Add seed nodes | ||||||||||||||||||||||||||
| seeds = None | ||||||||||||||||||||||||||
| if args.seed_nodes: | ||||||||||||||||||||||||||
| config = config.with_seeds(args.seed_nodes) | ||||||||||||||||||||||||||
| seeds = args.seed_nodes | ||||||||||||||||||||||||||
| elif rank > 0: | ||||||||||||||||||||||||||
| prev_port = 9000 + (rank - 1) | ||||||||||||||||||||||||||
| config = config.with_seeds([f"127.0.0.1:{prev_port}"]) | ||||||||||||||||||||||||||
| seeds = [f"127.0.0.1:{prev_port}"] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create system | ||||||||||||||||||||||||||
| system = await create_actor_system(config) | ||||||||||||||||||||||||||
| system = await pul.actor_system(addr=addr, seeds=seeds) | ||||||||||||||||||||||||||
| print(f"[Process {rank}] ActorSystem started at {system.addr}") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Wait for cluster to stabilize | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """ | ||
| Pulsing Ping-Pong Example using @remote decorator | ||
| Same functionality as AutoGen version | ||
| """ | ||
|
|
||
| from pulsing.actor import remote, runtime | ||
|
|
||
|
|
||
| # Define Agent | ||
| @remote | ||
| class PingPongAgent: | ||
| async def ping(self, message: str) -> str: | ||
| return f"pong: {message}" | ||
|
|
||
|
|
||
| # Run | ||
| async def main(): | ||
| async with runtime(): | ||
| agent = await PingPongAgent.spawn(name="pingpong") | ||
| response = await agent.ping("hello") | ||
| print(f"Received: {response}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import asyncio | ||
|
|
||
| asyncio.run(main()) |
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | |||||||||||||||||||||||||||||||||||||||||
| """ | |||||||||||||||||||||||||||||||||||||||||
| Pulsing Multi-Agent Research Workflow using @agent decorator | |||||||||||||||||||||||||||||||||||||||||
| Same functionality as AutoGen version | |||||||||||||||||||||||||||||||||||||||||
| """ | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| from pulsing.actor import resolve | |||||||||||||||||||||||||||||||||||||||||
| from pulsing.agent import agent, runtime | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Researcher Agent | |||||||||||||||||||||||||||||||||||||||||
| @agent(role="Researcher", goal="Research topics") | |||||||||||||||||||||||||||||||||||||||||
| class ResearcherAgent: | |||||||||||||||||||||||||||||||||||||||||
| async def research(self, topic: str) -> list[str]: | |||||||||||||||||||||||||||||||||||||||||
| return [ | |||||||||||||||||||||||||||||||||||||||||
| f"Research point 1 about {topic}", | |||||||||||||||||||||||||||||||||||||||||
| f"Research point 2 about {topic}", | |||||||||||||||||||||||||||||||||||||||||
| ] | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Analyst Agent | |||||||||||||||||||||||||||||||||||||||||
| @agent(role="Analyst", goal="Analyze research results") | |||||||||||||||||||||||||||||||||||||||||
| class AnalystAgent: | |||||||||||||||||||||||||||||||||||||||||
| async def analyze(self, points: list[str]) -> str: | |||||||||||||||||||||||||||||||||||||||||
| combined = " ".join(points) | |||||||||||||||||||||||||||||||||||||||||
| return f"Analysis: {combined[:50]}..." | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Reporter Agent | |||||||||||||||||||||||||||||||||||||||||
| @agent(role="Reporter", goal="Write final report") | |||||||||||||||||||||||||||||||||||||||||
| class ReporterAgent: | |||||||||||||||||||||||||||||||||||||||||
| async def write(self, summary: str) -> str: | |||||||||||||||||||||||||||||||||||||||||
| return f"Final Report:\n{summary}" | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Workflow | |||||||||||||||||||||||||||||||||||||||||
| async def run_workflow(): | |||||||||||||||||||||||||||||||||||||||||
| async with runtime(): | |||||||||||||||||||||||||||||||||||||||||
| # Spawn agents with names | |||||||||||||||||||||||||||||||||||||||||
| researcher = await ResearcherAgent.spawn(name="researcher") | |||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Variable defined multiple times Warning
This assignment to 'researcher' is unnecessary as it is
redefined Error loading related location Loading
Copilot AutofixAI 27 days ago In general, to fix “variable defined multiple times” when the first value is never used, you either remove the first assignment entirely or, if its right-hand side has important side effects, keep the call but drop the unused variable binding. The second assignment then becomes the only definition of the variable prior to its use. For this specific code in
No new imports or additional methods/definitions are needed; we only adjust these three lines within
Suggested changeset
1
comparison_examples/pulsing_research.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||
| analyst = await AnalystAgent.spawn(name="analyst") | |||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Variable defined multiple times Warning
This assignment to 'analyst' is unnecessary as it is
redefined Error loading related location Loading
Copilot AutofixAI 27 days ago In general, to fix “variable defined multiple times” where the first value is never used, you either remove the first assignment entirely (if it has no side effects) or keep the expression for its side effects and drop the unused variable binding. Here,
Concretely, in
No new methods or imports are needed.
Suggested changeset
1
comparison_examples/pulsing_research.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||
| reporter = await ReporterAgent.spawn(name="reporter") | |||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Variable defined multiple times Warning
This assignment to 'reporter' is unnecessary as it is
redefined Error loading related location Loading
Copilot AutofixAI 27 days ago In general, to fix “variable defined multiple times” when the first definition is never used, you either remove the earlier assignment entirely or keep the expression as a standalone call if you still need its side effects, without assigning its result to the same variable. In this file, the safest fix that preserves all possible side effects of
Concretely, in
No new imports or helper methods are required.
Suggested changeset
1
comparison_examples/pulsing_research.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Resolve by name (automatic load balancing) | |||||||||||||||||||||||||||||||||||||||||
| researcher = await resolve("researcher") | |||||||||||||||||||||||||||||||||||||||||
| analyst = await resolve("analyst") | |||||||||||||||||||||||||||||||||||||||||
| reporter = await resolve("reporter") | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| # Execute workflow | |||||||||||||||||||||||||||||||||||||||||
| research = await researcher.research("Quantum Computing") | |||||||||||||||||||||||||||||||||||||||||
| analysis = await analyst.analyze(research) | |||||||||||||||||||||||||||||||||||||||||
| report = await reporter.write(analysis) | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| print(report) | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | |||||||||||||||||||||||||||||||||||||||||
| import asyncio | |||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||
| asyncio.run(run_workflow()) | |||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,8 +87,8 @@ let system2 = ActorSystem::builder() | |
| .build() | ||
| .await?; | ||
|
|
||
| // 通过路径解析远程 Actor | ||
| let remote = system2.resolve_named("services/echo", None).await?; | ||
| // 通过名称解析远程 Actor | ||
| let remote = system2.resolve("services/echo").await?; | ||
| let resp: String = remote.ask("hello".to_string()).await?; | ||
| ``` | ||
|
|
||
|
|
@@ -97,18 +97,20 @@ let resp: String = remote.ask("hello".to_string()).await?; | |
| 除了传统 Actor trait,还提供函数式 Behavior API: | ||
|
|
||
| ```rust | ||
| use pulsing_actor::behavior::{stateful, BehaviorAction, BehaviorSpawner}; | ||
| use pulsing_actor::behavior::{stateful, Behavior, BehaviorAction}; | ||
| use pulsing_actor::prelude::*; | ||
|
|
||
| fn counter(initial: i32) -> Behavior<i32> { | ||
| stateful(initial, |count, n| { | ||
| stateful(initial, |count, n, _ctx| { | ||
| *count += n; | ||
| println!("count = {}", *count); | ||
| BehaviorAction::Same | ||
| }) | ||
| } | ||
|
|
||
| let system = ActorSystem::builder().build().await?; | ||
| let counter_ref = system.spawn_behavior("counter", counter(0)).await?; | ||
| // Behavior 实现 IntoActor,可以直接传给 spawn_named | ||
| let counter_ref = system.spawn_named("actors/counter", counter(0)).await?; | ||
|
|
||
| counter_ref.tell(5).await?; // count = 5 | ||
| counter_ref.tell(3).await?; // count = 8 | ||
|
|
||
Check notice
Code scanning / CodeQL
Unused import Note test
Copilot Autofix
AI 27 days ago
To fix an unused import, the general approach is to remove the unused name from the import statement (or delete the entire import if nothing in it is used). This preserves all existing functionality while cleaning up unnecessary dependencies.
In this case, in
benchmarks/large_scale_stress_test.py, the linefrom pulsing.actor import Actor, StreamMessage, SystemConfigshould be modified so that it only imports the names that are actually used:ActorandStreamMessage. Specifically, on line 21, removeSystemConfigfrom the imported names, resulting infrom pulsing.actor import Actor, StreamMessage. No other code changes are required, and no additional methods, imports, or definitions are needed, sinceSystemConfigis not referenced elsewhere in the provided snippet.