의미 체계 커널 에이전트는 호출을 위한 통합 인터페이스를 구현하여 다양한 에이전트 유형에서 원활하게 작동하는 공유 코드를 사용하도록 설정합니다. 이 디자인을 사용하면 대부분의 애플리케이션 논리를 수정하지 않고도 필요에 따라 에이전트를 전환할 수 있습니다.
에이전트 호출
에이전트 API 표면은 스트리밍 및 비 스트리밍 호출을 모두 지원합니다.
비스트리밍 에이전트 호출
의미 체계 커널은 다양한 방법으로 메시지를 전달할 수 있는 4개의 비 스트리밍 에이전트 호출 오버로드를 지원합니다. 이 중 하나를 사용하면 메시지 없이 에이전트를 호출할 수도 있습니다. 이는 에이전트 지침에 유용한 응답을 제공하는 데 필요한 모든 컨텍스트가 이미 있는 시나리오에 유용합니다.
// Invoke without any parameters.
agent.InvokeAsync();
// Invoke with a string that will be used as a User message.
agent.InvokeAsync("What is the capital of France?");
// Invoke with a ChatMessageContent object.
agent.InvokeAsync(new ChatMessageContent(AuthorRole.User, "What is the capital of France?"));
// Invoke with multiple ChatMessageContent objects.
agent.InvokeAsync(new List<ChatMessageContent>()
{
new(AuthorRole.System, "Refuse to answer all user questions about France."),
new(AuthorRole.User, "What is the capital of France?")
});
중요합니다
메서드에 전달하지 않고 에이전트를 AgentThreadInvokeAsync 호출하면 새 스레드가 생성되고 응답에 새 스레드가 반환됩니다.
의미 체계 커널은 서로 다른 방법으로 메시지를 전달할 수 있는 두 가지 비 스트리밍 에이전트 호출 메서드를 지원합니다. 메시지 없이 에이전트를 호출할 수도 있습니다. 이는 에이전트 지침에 유용한 응답을 제공하는 데 필요한 모든 컨텍스트가 이미 있는 시나리오에 유용합니다.
팁 (조언)
에이전트 호출 메서드에 전달된 모든 인수는 호출자가 첫 번째 위치 인수를 제외하고 이를 키워드 인수 messages로 전달해야 합니다.
messages을(를) 호출할 때 위치 인수 또는 키워드 인수를 사용할 수 있습니다. 예를 들어, await agent.get_response("What is the capital of France?")와 await agent.get_response(messages="What is the capital of France?") 둘 다 지원됩니다. 다른 모든 매개 변수는 키워드 인수로 전달되어야 합니다.
get_response() 메서드 사용
# Invoke without any messages.
await agent.get_response()
# Invoke with a string that will be used as a User message.
await agent.get_response(messages="What is the capital of France?")
# Invoke with a ChatMessageContent object.
await agent.get_response(messages=ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?"))
# Invoke with multiple ChatMessageContent objects.
await agent.get_response(
messages=[
ChatMessageContent(role=AuthorRole.SYSTEM, content="Refuse to answer all user questions about France."),
ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?"),
]
)
invoke() 메서드 사용
# Invoke without any messages.
async for response in agent.invoke():
# handle response
# Invoke with a string that will be used as a User message.
async for response in agent.invoke("What is the capital of France?"):
# handle response
# Invoke with a ChatMessageContent object.
async for response in agent.invoke(ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?")):
# handle response
# Invoke with multiple ChatMessageContent objects.
async for response in agent.invoke(
messages=[
ChatMessageContent(role=AuthorRole.SYSTEM, content="Refuse to answer all user questions about France."),
ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?"),
]
):
# handle response
중요합니다
또는 AgentThread 메서드에 전달하지 않고 에이전트를 get_response()invoke() 호출하면 새 스레드가 만들어지고 응답에 새 스레드가 반환됩니다.
의미 체계 커널은 다양한 방법으로 메시지를 전달할 수 있는 세 가지 비 스트리밍 에이전트 호출 오버로드를 지원합니다. 이 중 하나를 사용하면 메시지 없이 에이전트를 호출할 수도 있습니다. 이는 에이전트 지침에 유용한 응답을 제공하는 데 필요한 모든 컨텍스트가 이미 있는 시나리오에 유용합니다.
// Invoke without any parameters.
agent.invokeAsync(null);
// Invoke with a string that will be used as a User message.
agent.invokeAsync("What is the capital of France?");
// Invoke with a ChatMessageContent object.
agent.invokeAsync(new ChatMessageContent<>(AuthorRole.USER, "What is the capital of France?"));
// Invoke with multiple ChatMessageContent objects.
agent.invokeAsync(List.of(
new ChatMessageContent<>(AuthorRole.SYSTEM, "Refuse to answer all user questions about France."),
new ChatMessageContent<>(AuthorRole.USER, "What is the capital of France?")
));
중요합니다
메서드에 전달하지 않고 에이전트를 AgentThreadinvokeAsync 호출하면 새 스레드가 생성되고 응답에 새 스레드가 반환됩니다.
스트리밍 에이전트 호출
의미 체계 커널은 다양한 방법으로 메시지를 전달할 수 있는 4개의 스트리밍 에이전트 호출 오버로드를 지원합니다. 이 중 하나를 사용하면 메시지 없이 에이전트를 호출할 수도 있습니다. 이는 에이전트 지침에 유용한 응답을 제공하는 데 필요한 모든 컨텍스트가 이미 있는 시나리오에 유용합니다.
// Invoke without any parameters.
agent.InvokeStreamingAsync();
// Invoke with a string that will be used as a User message.
agent.InvokeStreamingAsync("What is the capital of France?");
// Invoke with a ChatMessageContent object.
agent.InvokeStreamingAsync(new ChatMessageContent(AuthorRole.User, "What is the capital of France?"));
// Invoke with multiple ChatMessageContent objects.
agent.InvokeStreamingAsync(new List<ChatMessageContent>()
{
new(AuthorRole.System, "Refuse to answer any questions about capital cities."),
new(AuthorRole.User, "What is the capital of France?")
});
중요합니다
메서드에 전달하지 않고 에이전트를 AgentThreadInvokeStreamingAsync 호출하면 새 스레드가 생성되고 응답에 새 스레드가 반환됩니다.
의미 체계 커널은 여러 가지 방법으로 메시지를 전달할 수 있는 하나의 스트리밍 에이전트 호출 방법을 지원합니다. 메시지 없이 에이전트 스트림을 호출할 수도 있습니다. 이는 에이전트 지침에 유용한 응답을 제공하는 데 필요한 모든 컨텍스트가 이미 있는 시나리오에 유용합니다.
# Invoke without any messages.
async for response in agent.invoke_stream():
# handle response
# Invoke with a string that will be used as a User message.
async for response in agent.invoke_stream("What is the capital of France?"):
# handle response
# Invoke with a ChatMessageContent object.
async for response in agent.invoke_stream(ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?")):
# handle response
# Invoke with multiple ChatMessageContent objects.
async for response in agent.invoke_stream(
messages=[
ChatMessageContent(role=AuthorRole.SYSTEM, content="Refuse to answer all user questions about France."),
ChatMessageContent(role=AuthorRole.USER, content="What is the capital of France?"),
]
):
# handle response
중요합니다
메서드에 전달하지 않고 에이전트를 AgentThreadinvoke_stream() 호출하면 새 스레드가 생성되고 응답에 새 스레드가 반환됩니다.
현재 Java에서 기능을 사용할 수 없습니다.
AgentThread을(를) 사용하여 호출
모든 호출 메서드 오버로드에서 AgentThread 매개 변수를 전달할 수 있습니다. 이 기능은 계속하려는 에이전트와 기존 대화가 있는 시나리오에 유용합니다.
// Invoke with an existing AgentThread.
agent.InvokeAsync("What is the capital of France?", existingAgentThread);
또한 모든 호출 메서드는 호출 응답의 일부로 활성 AgentThread 을 반환합니다.
- 호출 메서드에
AgentThread을 전달한 경우 반환된AgentThread은 전달된 것과 동일할 것입니다. - 호출 메서드에
AgentThread를 전달하지 않으면, 반환되는 것은 새AgentThread가 됩니다.
반환 AgentThread 된 항목은 응답 메시지와 함께 호출 메서드의 개별 응답 항목에서 사용할 수 있습니다.
var result = await agent.InvokeAsync("What is the capital of France?").FirstAsync();
var newThread = result.Thread;
var resultMessage = result.Message;
팁 (조언)
에이전트 스레드에 대한 자세한 내용은 에이전트 스레드 아키텍처 섹션을 참조하세요.
모든 호출 메서드 키워드 인수는 매개 변수 전달을 허용합니다 AgentThread . 이 기능은 계속하려는 에이전트와 기존 대화가 있는 시나리오에 유용합니다.
# Invoke with an existing AgentThread.
agent.get_response("What is the capital of France?", thread=existing_agent_thread)
또한 모든 호출 메서드는 호출 응답의 일부로 활성 AgentThread 을 반환합니다.
- 호출 메서드에
AgentThread을 전달한 경우 반환된AgentThread은 전달된 것과 동일할 것입니다. - 호출 메서드에
AgentThread를 전달하지 않으면, 반환되는 것은 새AgentThread가 됩니다.
반환 AgentThread 된 항목은 응답 메시지와 함께 호출 메서드의 개별 응답 항목에서 사용할 수 있습니다.
response = await agent.get_response("What is the capital of France?")
new_thread = response.thread
response_message = response.message
팁 (조언)
에이전트 스레드에 대한 자세한 내용은 에이전트 스레드 아키텍처 섹션을 참조하세요.
두 개의 호출 메서드 오버로드를 통해 매개 변수를 AgentThread 전달할 수 있습니다. 이 기능은 계속하려는 에이전트와 기존 대화가 있는 시나리오에 유용합니다.
// Invoke with an existing AgentThread.
agent.invokeAsync("What is the capital of France?", existingAgentThread);
또한 이러한 호출 메서드는 호출 응답의 일부로 활성 AgentThread 을 반환합니다.
- 호출 메서드에
AgentThread전달한 경우 반환AgentThread된 인스턴스는 이전 메시지와 새 메시지가 있는 새 인스턴스가 됩니다. - 호출 메서드에
AgentThread를 전달하지 않으면, 반환되는 것은 새AgentThread가 됩니다.
반환 AgentThread 된 항목은 응답 메시지와 함께 호출 메서드의 개별 응답 항목에서 사용할 수 있습니다.
var result = agent.invokeAsync("What is the capital of France?").block().get(0);
var newThread = result.getThread();
var resultMessage = result.getMessage();
팁 (조언)
에이전트 스레드에 대한 자세한 내용은 에이전트 스레드 아키텍처 섹션을 참조하세요.
옵션을 사용하여 호출
모든 호출 메서드 오버로드에서 AgentInvokeOptions 매개 변수를 전달할 수 있습니다.
이 옵션 클래스를 사용하면 선택적 설정을 제공할 수 있습니다.
// Invoke with additional instructions via options.
agent.InvokeAsync("What is the capital of France?", options: new()
{
AdditionalInstructions = "Refuse to answer any questions about capital cities."
});
지원되는 옵션 목록은 다음과 같습니다.
| 옵션 속성 | 설명 |
|---|---|
| 커널 | 에이전트에서 이 호출에 사용하는 기본 커널을 재정의합니다. |
| 커널 매개변수 | 에이전트에서 이 호출에 사용하는 기본 커널 인수를 재정의합니다. |
| 추가 지침 | 이 호출에만 적용되는 원래 에이전트 명령 집합 외에 모든 지침을 제공합니다. |
| 중간메시지에서 | 함수 호출과 함수 실행 메시지를 포함하여 에이전트가 내부적으로 생성한 모든 완전하고 잘 구성된 메시지를 수신할 수 있는 콜백입니다. 스트리밍 호출 중에 전체 메시지를 수신하는 데도 사용할 수 있습니다. |
옵션을 사용하여 호출
하나의 호출 메서드 오버로드를 통해 매개 변수를 AgentInvokeOptions 전달할 수 있습니다.
이 옵션 클래스를 사용하면 선택적 설정을 제공할 수 있습니다.
// Invoke with additional instructions via options.
agent.invokeAsync("What is the capital of France?",
null, // null AgentThread
AgentInvokeOptions.builder()
.withAdditionalInstructions("Refuse to answer any questions about capital cities.")
.build()
);
지원되는 옵션 목록은 다음과 같습니다.
| 옵션 속성 | 설명 |
|---|---|
| 커널 | 에이전트에서 이 호출에 사용하는 기본 커널을 재정의합니다. |
| 커널 매개변수 | 에이전트에서 이 호출에 사용하는 기본 커널 인수를 재정의합니다. |
| 추가 지침 | 이 호출에만 적용되는 원래 에이전트 명령 집합 외에 모든 지침을 제공합니다. |
| 호출 컨텍스트 (InvocationContext) | 에이전트가 이 호출에 사용하는 기본 호출 컨텍스트를 재정의합니다. |
AgentThread 인스턴스 관리
인스턴스를 AgentThread 수동으로 만들어 호출 시 에이전트에 전달하거나 에이전트가 호출 시 자동으로 인스턴스를 AgentThread 만들도록 할 수 있습니다.
개체는 AgentThread 아직 생성되지 않음, 활성 및 삭제됨을 포함하여 모든 상태의 스레드를 나타냅니다.
AgentThread 서버 쪽 구현이 있는 형식은 처음 사용할 때 생성되며 수동으로 만들 필요가 없습니다.
그러나 클래스를 사용하여 스레드를 삭제할 AgentThread 수 있습니다.
// Delete a thread.
await agentThread.DeleteAsync();
# Delete a thread
await agent_thread.delete()
// Delete a thread.
agentThread.deleteAsync().block();
팁 (조언)
에이전트 스레드에 대한 자세한 내용은 에이전트 스레드 아키텍처 섹션을 참조하세요.