| 
									
										
										
										
											2024-07-25 00:06:06 -07:00
										 |  |  | using System.Diagnostics; | 
					
						
							| 
									
										
										
										
											2024-06-28 08:03:42 -07:00
										 |  |  | using Agents; | 
					
						
							|  |  |  | using Microsoft.AI.Agents.Worker.Client; | 
					
						
							|  |  |  | using AgentId = Microsoft.AI.Agents.Worker.Client.AgentId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Greeter.AgentWorker; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 00:06:06 -07:00
										 |  |  | public sealed class AgentClient(ILogger<AgentClient> logger, AgentWorkerRuntime runtime, DistributedContextPropagator distributedContextPropagator) : AgentBase(new ClientContext(logger, runtime, distributedContextPropagator)) | 
					
						
							| 
									
										
										
										
											2024-06-28 08:03:42 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-07-19 13:57:13 -07:00
										 |  |  |     public async ValueTask PublishEventAsync(Event @event) => await PublishEvent(@event); | 
					
						
							|  |  |  |     public async ValueTask<RpcResponse> SendRequestAsync(AgentId target, string method, Dictionary<string, string> parameters) => await RequestAsync(target, method, parameters); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 00:06:06 -07:00
										 |  |  |     private sealed class ClientContext(ILogger<AgentClient> logger, AgentWorkerRuntime runtime, DistributedContextPropagator distributedContextPropagator) : IAgentContext | 
					
						
							| 
									
										
										
										
											2024-06-28 08:03:42 -07:00
										 |  |  |     { | 
					
						
							|  |  |  |         public AgentId AgentId { get; } = new AgentId("client", Guid.NewGuid().ToString()); | 
					
						
							|  |  |  |         public AgentBase? AgentInstance { get; set; } | 
					
						
							|  |  |  |         public ILogger Logger { get; } = logger; | 
					
						
							| 
									
										
										
										
											2024-07-25 00:06:06 -07:00
										 |  |  |         public DistributedContextPropagator DistributedContextPropagator { get; } = distributedContextPropagator; | 
					
						
							| 
									
										
										
										
											2024-06-28 08:03:42 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         public async ValueTask PublishEventAsync(Event @event) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             await runtime.PublishEvent(@event).ConfigureAwait(false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public async ValueTask SendRequestAsync(AgentBase agent, RpcRequest request) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             await runtime.SendRequest(AgentInstance!, request).ConfigureAwait(false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public async ValueTask SendResponseAsync(RpcRequest request, RpcResponse response) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             await runtime.SendResponse(response).ConfigureAwait(false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |