Skip to content
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

RPC over events #4414

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design/02 - Topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ For this subscription source should map directly to agent key.
This subscription will therefore receive all events for the following well known topics:

- `{AgentType}:` - General purpose direct messages. These should be routed to the approriate message handler.
- `{AgentType}:rpc_request` - RPC request messages. These should be routed to the approriate RPC handler.
- `{AgentType}:rpc_request={RequesterAgentType}` - RPC request messages. These should be routed to the approriate RPC handler.
- `{AgentType}:rpc_response={RequestId}` - RPC response messages. These should be routed back to the response future of the caller.
- `{AgentType}:error={RequestId}` - Error message that corresponds to the given request.
47 changes: 5 additions & 42 deletions protos/agent_worker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,11 @@ option csharp_namespace = "Microsoft.AutoGen.Abstractions";
import "cloudevent.proto";
import "google/protobuf/any.proto";

message TopicId {
string type = 1;
string source = 2;
}

message AgentId {
string type = 1;
string key = 2;
}

message Payload {
string data_type = 1;
string data_content_type = 2;
bytes data = 3;
}

message RpcRequest {
string request_id = 1;
optional AgentId source = 2;
AgentId target = 3;
string method = 4;
Payload payload = 5;
map<string, string> metadata = 6;
}

message RpcResponse {
string request_id = 1;
Payload payload = 2;
string error = 3;
map<string, string> metadata = 4;
}

message Event {
string topic_type = 1;
string topic_source = 2;
optional AgentId source = 3;
Payload payload = 4;
map<string, string> metadata = 5;
}

message RegisterAgentTypeRequest {
string request_id = 1;
string type = 2;
Expand Down Expand Up @@ -115,13 +80,11 @@ message SaveStateResponse {

message Message {
oneof message {
RpcRequest request = 1;
RpcResponse response = 2;
cloudevent.CloudEvent cloudEvent = 3;
RegisterAgentTypeRequest registerAgentTypeRequest = 4;
RegisterAgentTypeResponse registerAgentTypeResponse = 5;
AddSubscriptionRequest addSubscriptionRequest = 6;
AddSubscriptionResponse addSubscriptionResponse = 7;
cloudevent.CloudEvent cloudEvent = 1;
RegisterAgentTypeRequest registerAgentTypeRequest = 2;
RegisterAgentTypeResponse registerAgentTypeResponse = 3;
AddSubscriptionRequest addSubscriptionRequest = 4;
AddSubscriptionResponse addSubscriptionResponse = 5;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def __init__(self, description: str) -> None:
super().__init__(description=description)
self._fifo_lock = FIFOLock()

async def on_message(self, message: Any, ctx: MessageContext) -> Any | None:
async def on_message_impl(self, message: Any, ctx: MessageContext) -> None:
await self._fifo_lock.acquire()
try:
return await super().on_message(message, ctx)
await super().on_message_impl(message, ctx)
finally:
self._fifo_lock.release()
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -211,7 +211,6 @@
"await runtime.send_message(\n",
" Message(\"Joe, tell me a joke.\"),\n",
" recipient=AgentId(joe, \"default\"),\n",
" sender=AgentId(cathy, \"default\"),\n",
")\n",
"await runtime.stop_when_idle()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
" def __init__(self) -> None:\n",
" super().__init__(\"MyAgent\")\n",
"\n",
" async def on_message(self, message: MyMessageType, ctx: MessageContext) -> None:\n",
" async def on_message_impl(self, message: MyMessageType, ctx: MessageContext) -> None:\n",
" print(f\"Received message: {message.content}\") # type: ignore"
]
},
Expand Down
Loading
Loading