Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bu belge, Microsoft Agent Framework İş Akışı sisteminin Yürütücüler bileşenine ayrıntılı bir bakış sağlar.
Genel Bakış
Yürütücüler, bir iş akışındaki iletileri işleyen temel yapı taşlarıdır. Bunlar, yazılan iletileri alan, işlemler gerçekleştiren ve çıkış iletileri veya olaylar üretebilen otonom işlem birimleridir.
Yürütücüler Executor<TInput, TOutput> temel sınıfından devralır. Her yürütücü benzersiz bir tanımlayıcıya sahiptir ve belirli ileti türlerini işleyebilir.
Temel Yürütücü Yapısı
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Reflection;
internal sealed class UppercaseExecutor() : Executor<string, string>("UppercaseExecutor")
{
public async ValueTask<string> HandleAsync(string message, IWorkflowContext context)
{
string result = message.ToUpperInvariant();
return result; // Return value is automatically sent to connected executors
}
}
Bir değer döndürmeden iletileri el ile göndermek mümkündür:
internal sealed class UppercaseExecutor() : Executor<string>("UppercaseExecutor")
{
public async ValueTask HandleAsync(string message, IWorkflowContext context)
{
string result = message.ToUpperInvariant();
await context.SendMessageAsync(result); // Manually send messages to connected executors
}
}
Yöntemini geçersiz kılarak ConfigureRoutes birden çok giriş türünü işlemek de mümkündür:
internal sealed class SampleExecutor() : Executor("SampleExecutor")
{
protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder)
{
return routeBuilder
.AddHandler<string>(this.HandleStringAsync)
.AddHandler<int>(this.HandleIntAsync);
}
/// <summary>
/// Converts input string to uppercase
/// </summary>
public async ValueTask<string> HandleStringAsync(string message, IWorkflowContext context)
{
string result = message.ToUpperInvariant();
return result;
}
/// <summary>
/// Doubles the input integer
/// </summary>
public async ValueTask<int> HandleIntAsync(int message, IWorkflowContext context)
{
int result = message * 2;
return result;
}
}
Uzantı yöntemini kullanarak BindExecutor bir işlevden yürütücü oluşturmak da mümkündür:
Func<string, string> uppercaseFunc = s => s.ToUpperInvariant();
var uppercase = uppercaseFunc.BindExecutor("UppercaseExecutor");
Yürütücüler Executor temel sınıfından devralır. Her yürütücü benzersiz bir tanımlayıcıya sahiptir ve dekoratörle @handler birlikte düzenlenmiş yöntemleri kullanarak belirli ileti türlerini işleyebilir. İşleyicilerin işleyebileceği ileti türünü belirtmek için uygun ek açıklamaya sahip olması gerekir.
Temel Yürütücü Yapısı
from agent_framework import (
Executor,
WorkflowContext,
handler,
)
class UpperCase(Executor):
@handler
async def to_upper_case(self, text: str, ctx: WorkflowContext[str]) -> None:
"""Convert the input to uppercase and forward it to the next node.
Note: The WorkflowContext is parameterized with the type this handler will
emit. Here WorkflowContext[str] means downstream nodes should expect str.
"""
await ctx.send_message(text.upper())
Dekoratör kullanarak @executor bir işlevden yürütücü oluşturmak mümkündür:
from agent_framework import (
WorkflowContext,
executor,
)
@executor(id="upper_case_executor")
async def upper_case(text: str, ctx: WorkflowContext[str]) -> None:
"""Convert the input to uppercase and forward it to the next node.
Note: The WorkflowContext is parameterized with the type this handler will
emit. Here WorkflowContext[str] means downstream nodes should expect str.
"""
await ctx.send_message(text.upper())
Birden çok işleyici tanımlayarak birden çok giriş türünü işlemek de mümkündür:
class SampleExecutor(Executor):
@handler
async def to_upper_case(self, text: str, ctx: WorkflowContext[str]) -> None:
"""Convert the input to uppercase and forward it to the next node.
Note: The WorkflowContext is parameterized with the type this handler will
emit. Here WorkflowContext[str] means downstream nodes should expect str.
"""
await ctx.send_message(text.upper())
@handler
async def double_integer(self, number: int, ctx: WorkflowContext[int]) -> None:
"""Double the input integer and forward it to the next node.
Note: The WorkflowContext is parameterized with the type this handler will
emit. Here WorkflowContext[int] means downstream nodes should expect int.
"""
await ctx.send_message(number * 2)
WorkflowContext Nesne
nesnesi, WorkflowContext işleyicinin yürütme sırasında iş akışıyla etkileşim kurması için yöntemler sağlar.
WorkflowContext, işleyicinin yayacağı ileti türü ve verebileceği çıkış türüyle parametrelenir.
En yaygın kullanılan yöntem, işleyicinin bağlı yürütücülere ileti göndermesine olanak tanıyan yöntemidir send_message.
from agent_framework import WorkflowContext
class SomeHandler(Executor):
@handler
async def some_handler(message: str, ctx: WorkflowContext[str]) -> None:
await ctx.send_message("Hello, World!")
İşleyici, iş akışı çıkışları olarak kabul edilecek ve çağırana çıkış olayı olarak döndürülecek/akışa alınabilecek çıkışlar üretmek için kullanabilir yield_output :
from agent_framework import WorkflowContext
class SomeHandler(Executor):
@handler
async def some_handler(message: str, ctx: WorkflowContext[Never, str]) -> None:
await ctx.yield_output("Hello, World!")
İşleyici mesaj göndermez veya çıktı üretmezse, WorkflowContext için tür parametresi gerekmez:
from agent_framework import WorkflowContext
class SomeHandler(Executor):
@handler
async def some_handler(message: str, ctx: WorkflowContext) -> None:
print("Doing some work...")
Sonraki Adım
- Yürütücülerin bir iş akışında nasıl bağlı olduğunu anlamak için Edge'ler hakkında bilgi edinin.