ข้ามไปยังเนื้อหา
AggregaAggregaAggregaAggrega
เลือกภาษา: ไทย
หน้านี้ถูกแปลด้วยเครื่อง อ่านต้นฉบับภาษาอังกฤษ

นำเข้าเอเจนต์เชิงประกาศของ Microsoft Agent Framework

บทแนะนำทีละขั้นตอนนี้นำเข้าเอเจนต์เชิงประกาศของ Microsoft Agent Framework — ผู้ช่วยที่ตอบคำถามจากเอกสารประกอบที่ค้นผ่านเซิร์ฟเวอร์ MCP — และบิลด์แอปพลิเคชันสำหรับ Docker Compose การนำเข้าร่างทุกไฟล์ที่บิลด์อ่าน ได้แก่เอเจนต์และโมเดล คีย์ที่เอเจนต์ส่งให้โมเดลเป็นการอ้างอิงตัวแปร และการทำให้เป็นรูปธรรมของแต่ละรายการ การนำเข้าถามเพียงครั้งเดียวสำหรับค่าเดียวที่เอเจนต์เชิงประกาศไม่มี คืออิมเมจที่แอปพลิเคชันของคุณรัน ทุกไฟล์และทุกบล็อกของเอาต์พุตด้านล่างมาจากการรันจริง เอเจนต์เชิงประกาศและแต่ละขั้นตอนของบทแนะนำอยู่ในตัวอย่าง import-agent-framework ซึ่งสคริปต์ตรวจสอบจะรันการนำเข้าอีกครั้ง เปรียบเทียบสิ่งที่เขียน สิ่งที่พิมพ์ และบล็อกที่หน้านี้อ้างอิงกับไฟล์ที่เก็บไว้ที่นั่น แล้วตรวจสอบความถูกต้องและบิลด์สิ่งที่การนำเข้าเขียน

ร่างตัวอย่าง

คุณรันการนำเข้านี้ด้วยคำสั่งในหน้านี้ได้ หรือ ให้ผู้ช่วย AI ของคุณรันให้

เขียนตัวอย่างลงในโฟลเดอร์ใหม่ที่ตั้งชื่อตามตัวอย่าง:

Terminal window
aggrega draft --example import-agent-framework

จากนั้นจะพิมพ์คำสั่งที่ต้องรันต่อ คำสั่งแรกเปลี่ยนเข้าโฟลเดอร์ใหม่ ส่วนคำสั่งถัดไปด้านล่างเปลี่ยนเข้าโฟลเดอร์ source ซึ่งมีสิ่งที่หน้านี้นำเข้าและเป็นที่ที่การนำเข้ารัน:

Terminal window
cd import-agent-framework

โฟลเดอร์ source ของตัวอย่างที่ร่างไว้ เปิดอยู่ใน Visual Studio Code แสดงเอเจนต์แบบพรอมต์ SupportAgent พร้อมโมเดล OpenAI และเครื่องมือ MCP ของ Microsoft Learn

โปรเจกต์

แอปพลิเคชันที่สร้างบน Agent Framework โหลดเอเจนต์จากเอเจนต์เชิงประกาศได้ ซึ่งเป็นเอกสาร YAML ประเภท Prompt ที่ระบุโมเดล คำแนะนำ และเครื่องมือของเอเจนต์ ไฟล์นี้เขียนขึ้นสำหรับบทแนะนำนี้ ระบุ gpt-4.1-mini ของ OpenAI และเซิร์ฟเวอร์ MCP ที่ Microsoft Learn เผยแพร่:

kind: Prompt
name: SupportAgent
displayName: Support Assistant
description: Answers a customer's question about the product from its documentation.
instructions: You answer customers' questions about the product, from its documentation only.
model:
id: gpt-4.1-mini
provider: OpenAI
apiType: Responses
options:
temperature: 0.2
connection:
kind: key
key: =Env.OPENAI_API_KEY
tools:
- kind: mcp
name: microsoft_learn
description: Search Microsoft's documentation on Microsoft Learn.
url: https://learn.microsoft.com/api/mcp
approvalMode:
kind: never
allowedTools:
- microsoft_docs_search
- microsoft_docs_fetch

คีย์ของโมเดลเขียนเป็น =Env.OPENAI_API_KEY ไฟล์จึงไม่มีคีย์ Agent Framework อ่านนิพจน์นั้นจากตัวแปรสภาพแวดล้อม OPENAI_API_KEY ก็ต่อเมื่อแอปพลิเคชันโหลดเอเจนต์เชิงประกาศด้วย AgentFactory(safe_mode=False) ซึ่งเป็นการตั้งค่าความปลอดภัยของ Agent Framework เอง และมีรันไทม์ .NET อยู่ มิฉะนั้นคีย์คือข้อความของนิพจน์ตามที่เขียน การนำเข้าไม่อ่านโค้ดของแอปพลิเคชันที่โหลดเอเจนต์เชิงประกาศเลย และโค้ดนั้นไม่เป็นส่วนของตัวอย่าง ข้างไฟล์นั้น .aggrega-config.yaml ทำให้โฟลเดอร์เป็นพื้นที่ทำงาน:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside support-agent.yaml.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

การนำเข้าอ้างอิง Components ของเอเจนต์ Agent Framework และโมเดล OpenAI ในแค็ตตาล็อก และ --target ร่าง Manifest จาก Recipes ของแค็ตตาล็อก พื้นที่ทำงานไม่ระบุโฟลเดอร์แค็ตตาล็อก การนำเข้าจึงอ่านแค็ตตาล็อกไลบรารีมาตรฐานจากรีจิสทรีที่ดึงตัวนำเข้ามา: สแนปช็อตที่ลงลายเซ็นของแค็ตตาล็อกที่เผยแพร่ ซึ่งการนำเข้าครั้งแรกดึง ยืนยัน และเก็บไว้ในแคชเนื้อหาของพื้นที่ทำงาน และระบุด้วยไดเจสต์ในบันทึกที่การนำเข้าเขียนไว้ข้างฉบับร่าง พื้นที่ทำงานที่ระบุโฟลเดอร์แค็ตตาล็อกของตนเอง — ใน AGGREGA_CATALOG_DIRS หรือภายใต้ workspace.catalog_dirs — อ่านโฟลเดอร์เหล่านั้นก่อน โดยมีสแนปช็อตที่เผยแพร่อยู่ถัดมา

สิ่งที่การนำเข้าถาม

เอเจนต์เชิงประกาศระบุโมเดลของตน ไม่ระบุอิมเมจที่แอปพลิเคชันรัน เพราะคุณบิลด์อิมเมจนั้นจากโปรเจกต์ของคุณ แค็ตตาล็อกไม่มีอิมเมจเริ่มต้นสำหรับแอปพลิเคชันที่สร้างบน Agent Framework การนำเข้าจึงถามหา เมื่อรันที่เทอร์มินัลโดยไม่มีคำตอบอยู่ในมือ การนำเข้าถามว่า:

The drafts leave values empty that the source cannot hold. Answer each one, or press Enter to leave it for later in the answers file:
release.yaml spec.components.supportagent.infra.image
Container image running the application built on Microsoft Agent Framework.
>

และเขียนคำตอบลงในฉบับร่างและใน import-answers.yaml ข้าง support-agent.yaml การนำเข้าครั้งต่อไปจึงอ่านจากที่นั่นและไม่ถามอะไร เมื่อไม่มีเทอร์มินัล — ใน continuous integration หรือผ่านไปป์ — การนำเข้าไม่ถามอะไร: เขียนไฟล์โดยปล่อยคีย์ว่าง แล้วหยุดและระบุชื่อไฟล์ ตัวอย่างมีไฟล์นี้อยู่แล้ว โดยตอบอิมเมจไว้เป็น ghcr.io/example/support-agent:1.0.0 ซึ่งแทนอิมเมจที่คุณบิลด์:

# Values the import could not draft from the source, keyed by the drafted file and the key path inside
# it. Write each one beside its key; an import of the same source, and a sync, read them from here and
# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable
# name, ${NAME}, or the name of a Kubernetes Secret.
release.yaml:
# Container image running the application built on Microsoft Agent Framework.
spec.components.supportagent.infra.image: "ghcr.io/example/support-agent:1.0.0"
# The origin of the secret value, written by the operator in the Release. Read exactly as
# values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes
# from, never the value.
spec.components.supportagent.uses.model.gpt-4-1-mini.features.credential.infra.origin: "openai-api-key"

คำตอบที่สองสำหรับบิลด์สำหรับ Kubernetes ด้วย --target helm: ในกรณีนั้นเอเจนต์อ่านคีย์ OpenAI จาก Kubernetes Secret และคำตอบคือชื่อของ Secret คือ openai-api-key ไม่ใช่คีย์ บิลด์สำหรับ Docker Compose อ่านคีย์จาก shell ของคุณแทน การนำเข้านี้จึงไม่ใช้คำตอบนั้น ไฟล์คำตอบของการนำเข้า อธิบายไฟล์ คำถาม และกฎสำหรับคำตอบของข้อมูลลับ

aggrega import ระบุทุกแฟล็กที่คำสั่งรับ รวมถึง --answers ซึ่งระบุไฟล์คำตอบที่เก็บไว้ที่อื่น

เปลี่ยนเข้าโฟลเดอร์ source:

Terminal window
cd source

รันการนำเข้า

ระบุไฟล์ของเอเจนต์เชิงประกาศ การนำเข้าอ่านเอเจนต์เชิงประกาศแต่ละตัวเป็นไฟล์หนึ่งไฟล์ และไม่อ่านเป็นไดเรกทอรี:

Terminal window
aggrega import support-agent.yaml --target compose

ที่เอาต์พุตมาตรฐาน การนำเข้าแสดงสิ่งที่เขียน:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote .aggrega-import.json

ที่ข้อผิดพลาดมาตรฐาน โดยที่ <workspace> แทนโฟลเดอร์ที่คุณรัน:

[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]
read as the agent-framework format, with drafted paths relative to <workspace>
warn: the value of tools.microsoft_learn.url of node SupportAgent is carried as written in the Release the draft writes: the field belongs to an MCP server's configuration, which can carry a key, and setting empty_credentials to marked or all writes it empty
info: the answers file <workspace>/import-answers.yaml also answers spec.components.supportagent.uses.model.gpt-4-1-mini.features.credential.infra.origin in release.yaml, which these drafts do not leave empty; those answers are kept there and not applied
mapped SupportAgent (agent) to core/ai-agent/agent-framework as a reference, NONE
mapped gpt-4.1-mini (model) to core/ai-model/openai as a reference, NONE
made no choice for SupportAgent#microsoft_learn (tool)
Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)

การนำเข้าที่รันจากตัวแก้ไข: Aggregate, Release และ Manifest ที่ร่างปรากฏข้างเอเจนต์เชิงประกาศ เอาต์พุตของ Aggrega แสดงว่าแมปเอเจนต์และโมเดลอย่างไรและไฟล์ที่เขียน และการแจ้งเตือนบอกว่าการนำเข้าร่างไฟล์ 3 ไฟล์ โดยรู้จักเป็น agent-framework

  • บรรทัด warn ระบุค่าที่อาจมีคีย์ — ที่อยู่ของเซิร์ฟเวอร์ MCP — และบอกว่านำมาตามที่เขียน ที่อยู่นี้ไม่มีคีย์
  • บรรทัด info ระบุคำตอบที่ฉบับร่างสำหรับ Docker Compose ไม่ใช้ ซึ่งเก็บไว้ในไฟล์คำตอบสำหรับบิลด์สำหรับ Kubernetes
  • บรรทัด mapped บอกว่าเอเจนต์เป็นอินสแตนซ์ของเอเจนต์ Agent Framework ของไลบรารีมาตรฐาน คือ core/ai-agent/agent-framework และโมเดลของเอเจนต์เป็นอินสแตนซ์ของ core/ai-model/openai ระดับของทั้งสองเป็น NONE: การนำเข้า Agent Framework อ้างอิง Components เหล่านี้ตามสิ่งที่เอเจนต์เชิงประกาศระบุ แทนที่จะเทียบแต่ละรายการกับแค็ตตาล็อก
  • บรรทัด made no choice คือเซิร์ฟเวอร์ MCP ซึ่งการนำเข้าไม่ร่างเป็น Component ใดด้วยเหตุผลที่ความคิดเห็นใน aggregate.yaml ให้ไว้
  • บรรทัด Pull complete คือการนำเข้าดึงสิ่งที่ Release ที่ร่างพึ่งพา เหมือนที่ aggrega pull ทำ ลงใน release.lock ฉบับร่างจึงตรวจสอบความถูกต้องและบิลด์ได้ทันที ภายใต้ --offline การนำเข้าไม่ pull สิ่งใดและระบุ aggrega pull ที่ต้องรัน

สิ่งที่การนำเข้าเขียน

Aggregate, Release และ Manifest ชื่อ imported/supportagent ตามชื่อ name ของเอเจนต์ คือ SupportAgent ที่ย่อเหลือ supportagent — ไม่อ่าน displayName ของเอเจนต์ — ภายใต้เนมสเปซที่การตั้งค่า target_namespace ของตัวนำเข้ากำหนด คือ imported เว้นแต่คุณตั้งค่าอื่น (การตั้งค่า)

aggregate.yaml — เอเจนต์ที่เชื่อมโยงกับโมเดลของตน โดยประกาศคีย์ที่เอเจนต์ส่งไว้บนการเชื่อมต่อ และโมเดล:

# Not read: the application's code, which loads each declarative agent and binds the functions of its function tools; the application runs in the image the Release names for each instance, and loads its declarative agents itself.
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/supportagent
version: 0.1.0
description: Draft Aggregate imported from a source in the agent-framework format.
spec:
components:
# The declarative agent SupportAgent.
# Read by the application from the declarative agent, and taken by no key of core/ai-agent/agent-framework: instructions, the options of its model requests (temperature).
# The MCP server microsoft_learn, drafted as no Component and no connection, since Agent Framework sends it to the model's provider as a hosted tool, and the provider, not the application, reaches it at its url, which must therefore be reachable from the provider; its url is written above supportagent's entry in the Release.
# Stated by the declarative agent for microsoft_learn: its description, "Search Microsoft's documentation on Microsoft Learn."; its approval mode, never; the tools of the server it allows, microsoft_docs_search, microsoft_docs_fetch.
supportagent:
type: core/ai-agent/agent-framework
values:
display_name: "Support Assistant"
description: "Answers a customer's question about the product from its documentation."
uses:
model:
gpt-4-1-mini:
target: gpt-4-1-mini
# For the compose target, the lines below declare credential on gpt-4-1-mini: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none.
features:
credential:
type: core/secret-value
values:
key: OPENAI_API_KEY
# The model gpt-4.1-mini, which SupportAgent names with the OpenAI provider.
gpt-4-1-mini:
type: core/ai-model/openai
values:
model: "gpt-4.1-mini"

เซิร์ฟเวอร์ MCP ไม่ใช่ Component และไม่ใช่การเชื่อมต่อของเอเจนต์: Agent Framework ส่งเซิร์ฟเวอร์นั้นไปยังผู้ให้บริการของโมเดลเป็นเครื่องมือที่โฮสต์ไว้ และผู้ให้บริการ ไม่ใช่แอปพลิเคชัน เป็นฝ่ายเข้าถึงที่ url ของเซิร์ฟเวอร์ ซึ่งจึงต้องเข้าถึงได้จากผู้ให้บริการ คำแนะนำ ตัวเลือกของคำขอไปยังโมเดล และคำอธิบาย โหมดการอนุมัติ และเครื่องมือที่อนุญาตของเซิร์ฟเวอร์ ยังอยู่ในเอเจนต์เชิงประกาศ ซึ่งแอปพลิเคชันอ่าน ความคิดเห็นระบุแต่ละรายการ API ของ OpenAI เป็นบริการที่โฮสต์ไว้ Component ของเอเจนต์จึงปฏิเสธการเชื่อมต่อไปยัง API นั้นที่ไม่มีข้อมูลรับรอง การเชื่อมต่อประกาศข้อมูลรับรองหนึ่งรายการ ใต้คีย์ OPENAI_API_KEY ซึ่งเป็นตัวแปรที่เอเจนต์เชิงประกาศอ่านคีย์ของตน

release.yaml — สภาพแวดล้อม อิมเมจ พอร์ตที่เผยแพร่ และที่มาของคีย์:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/supportagent
# environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to.
environment: development
version: 0.1.0
description: Draft Release imported from a source in the agent-framework format.
spec:
aggregate: imported/supportagent
manifest: imported/supportagent
components:
# The declarative agent also states these values for its model and its MCP servers, written here for review:
# - model.connection.key, written as =Env.OPENAI_API_KEY, which Agent Framework reads from the environment variable OPENAI_API_KEY only where the application loads the declarative agent with AgentFactory(safe_mode=False), Agent Framework's own security setting, and a .NET runtime is present; otherwise the value is the expression's text as written
# - tools.microsoft_learn.url: "https://learn.microsoft.com/api/mcp"
supportagent:
infra:
# Left for the Release, since the source cannot supply it: infra.image, the container image running the application built on Agent Framework, holding its declarative agent
image: "ghcr.io/example/support-agent:1.0.0"
# Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal.
published_port: 8000
uses:
model:
gpt-4-1-mini:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential supportagent presents to gpt-4-1-mini on its model connection, read from the variable OPENAI_API_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
origin: "${OPENAI_API_KEY}"
gpt-4-1-mini: {}

สภาพแวดล้อม development เป็นค่าเริ่มต้นที่การนำเข้าเขียนเพราะไม่มีเอเจนต์เชิงประกาศใดระบุ เปลี่ยนเมื่อ Release ปรับใช้ที่อื่น อิมเมจคือคำตอบที่การนำเข้าอ่านจาก import-answers.yaml เอเจนต์เผยแพร่ที่ที่อยู่ลูปแบ็กของเครื่องคุณ ที่พอร์ต 8000 ส่งต่อไปยังพอร์ตที่โปรแกรมของเอเจนต์ฟัง คือ infra.port ซึ่งเป็น 8000 เว้นแต่คุณตั้งค่าอื่น คีย์คือการอ้างอิงตัวแปร ${OPENAI_API_KEY} ซึ่งตั้งชื่อตามตัวแปรที่เอเจนต์เชิงประกาศอ่าน ไม่ใช่ค่า ที่อยู่ของเซิร์ฟเวอร์ MCP เขียนตามที่เอเจนต์เชิงประกาศระบุ เพื่อให้ตรวจทาน และไม่ตั้งที่อื่น: Agent Framework ส่งที่อยู่ให้ผู้ให้บริการในคำขอไปยังโมเดล

manifest.yaml — Compose Recipe ของเอเจนต์และของโมเดล และการทำให้เป็นรูปธรรมที่เขียนการอ้างอิงตัวแปรของคีย์ลงในไฟล์ Compose ตามที่เขียน:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/supportagent
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/agent-framework: compose/agent-framework
core/ai-model/openai: compose/openai
features:
type:
core/secret-value: compose/dotenv-secret

release.lock บันทึกเอนทิตีในแค็ตตาล็อกที่ Release หาค่าได้ ตามไดเจสต์ และ .aggrega-import.json เป็นบันทึกของสิ่งที่การนำเข้าเขียน ซึ่ง aggrega import --sync ครั้งต่อไปอ่าน

ตรวจสอบความถูกต้องและบิลด์

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml

Release ที่ร่างเปิดอยู่ในตัวแก้ไขหลังตรวจสอบความถูกต้อง โดยเอาต์พุตของ Aggrega และการแจ้งเตือนต่างรายงานว่าไม่พบปัญหา

บิลด์ของ Release ที่ร่าง: โฟลเดอร์ dist ปรากฏใน Explorer เอาต์พุตของ Aggrega แสดงไฟล์ Docker Compose ที่เขียน และการแจ้งเตือนบอกว่าเขียนไฟล์แล้ว

การตรวจสอบความถูกต้องพิมพ์:

notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
release dependency validation passed: release.yaml (schema-pillar + dependency pillars)

และบิลด์ โดยที่ <workspace> แทนโฟลเดอร์ที่คุณรัน:

notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
[… omitted: a total build time, which differs per run]
Build completed: 1 file written to <workspace>/dist

บรรทัด notice เป็นเชิงแนะนำ: Feature ของข้อมูลลับรับ origin จาก values ของ Aggregate หรือ infra ของ Release และการแจ้งให้ทราบรายงานว่ามีค่าระดับใบหนึ่งค่าที่ประกาศไว้ทั้งสองที่ ซึ่งไม่เปลี่ยนคำตัดสิน

บริการของเอเจนต์ใน dist/compose/docker-compose.yaml:

services:
supportagent:
image: ghcr.io/example/support-agent:1.0.0
environment:
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_MODEL: gpt-4.1-mini
OPENAI_API_KEY: ${OPENAI_API_KEY}
ports:
- 127.0.0.1:8000:8000
[… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version]
networks:
- compose

แอปพลิเคชันได้รับที่อยู่ ชื่อ และคีย์ของโมเดลในตัวแปรที่ไคลเอนต์ OpenAI ของ Agent Framework อ่าน ดังนั้น =Env.OPENAI_API_KEY ของเอเจนต์เชิงประกาศจึงอ่านคีย์ที่ Release แนบไว้ ตรงที่แอปพลิเคชันโหลดตามที่ โปรเจกต์ อธิบาย ไม่มีตัวแปรใดเก็บที่อยู่ของเซิร์ฟเวอร์ MCP ซึ่งผู้ให้บริการเป็นฝ่ายเข้าถึง โมเดลไม่มีบริการของตนเอง: เอเจนต์เข้าถึง API ของ OpenAI ที่ที่อยู่ของ API นั้นเอง คีย์เป็นการอ้างอิงตัวแปรที่เติมจาก shell ของคุณเมื่อสแตกเริ่มทำงาน บริการเผยแพร่พอร์ตบน 127.0.0.1 เท่านั้น

กับผู้ช่วย AI

ผู้ช่วย AI ที่ ตั้งค่าด้วยเครื่องมือของ Aggrega ทำสิ่งเดียวกันได้: วางพรอมต์นี้ลงไป

ใช้เฉพาะเครื่องมือของ Aggrega และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์พื้นที่ทำงานยังไม่มีโฟลเดอร์ `import-agent-framework` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `import-agent-framework` และไม่ตั้ง `dir`: เครื่องมือนี้เขียนตัวอย่างลงในโฟลเดอร์ `import-agent-framework` ใหม่ ซึ่งโฟลเดอร์ `source` ของโฟลเดอร์นั้นมีสิ่งที่หน้านี้นำเข้า จากนั้นเรียกเครื่องมือ `import` โดยตั้ง `workspace_root` เป็น `import-agent-framework/source` ตั้ง `source` เป็น `support-agent.yaml` และตั้ง `target` เป็น `compose`: เครื่องมือนี้อ่านคำตอบที่ต้องใช้จาก `import-answers.yaml` ข้าง `support-agent.yaml` เขียนฉบับร่างลงใน `import-agent-framework/source` และ pull สิ่งที่ฉบับร่างต้องใช้ จากนั้นเรียกเครื่องมือ `validate` โดยตั้ง `workspace_root` เป็น `import-agent-framework/source` และ `release` เป็น `release.yaml` และเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `import-agent-framework/source` ตั้ง `release` เป็น `release.yaml` และตั้ง `write` เป็น true บอกฉันว่าบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `import-agent-framework/source/dist/`

เปิดใน VS Code

เมื่อติดตั้ง ส่วนขยาย Aggrega สำหรับ Visual Studio Code แล้ว เปิดโฟลเดอร์ import-agent-framework/source ใน VS Code ซึ่งเป็นที่ที่การนำเข้าเขียนฉบับร่าง โฟลเดอร์มี Release เดียว คือ release.yaml ที่ร่าง ตัวแก้ไขจึงเลือกให้คุณ และตรวจสอบฉบับร่างเทียบกับ Release นั้นขณะที่คุณแก้ไข โดยทำเครื่องหมายสิ่งที่พบในไฟล์และในแผง Problems Aggrega: Show topology graph ใน Command Palette วาดส่วนประกอบของ Release และการเชื่อมต่อระหว่างส่วนประกอบเหล่านั้น Aggrega: Build, Aggrega: Preview build และ Aggrega: Pull ทำงานกับ Release เดียวกัน และแต่ละคำสั่งยังเป็นปุ่มในแผง Commands ของมุมมอง Aggrega ในแถบกิจกรรม Build เขียนไฟล์ลงใน dist/ ของโฟลเดอร์ ใช้ Aggrega ใน Visual Studio Code ครอบคลุมส่วนที่เหลือ

วิธีรัน

คุณบิลด์อิมเมจจากโปรเจกต์ด้วย Dockerfile ของคุณเอง: โค้ดของแอปพลิเคชันที่ติดตั้ง Agent Framework และมีเอเจนต์เชิงประกาศอยู่ข้างใน Docker Compose รันคำสั่งของอิมเมจเองเป็นบริการของเอเจนต์ เพราะ Recipe ไม่ตั้งคำสั่งไว้ คำสั่งนั้นจึงต้องรันต่อเนื่อง และต้องรับคำขอหากคุณต้องการเข้าถึงเอเจนต์ โปรแกรมของคุณกำหนดที่อยู่ เส้นทาง และการตอบกลับ

การรันด้านล่างใช้อิมเมจเช่นนั้น: Python พร้อมแพ็กเกจ agent-framework-core, agent-framework-openai และ agent-framework-declarative ของ Agent Framework รันไทม์ .NET — อิมเมจตั้ง DOTNET_ROOT เป็นไดเรกทอรีของรันไทม์ และ DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 — support-agent.yaml และคำสั่งของอิมเมจเป็นเซิร์ฟเวอร์ HTTP ขนาดเล็กของโปรแกรมเองบนพอร์ต 8000 เซิร์ฟเวอร์โหลดเอเจนต์เชิงประกาศด้วย AgentFactory(safe_mode=False) ดังนั้น =Env.OPENAI_API_KEY ของเซิร์ฟเวอร์จึงอ่านคีย์ที่บิลด์ส่งมอบ และรันเอเจนต์หนึ่งรอบต่อ POST /ask แต่ละครั้ง บิลด์อิมเมจของคุณที่รากของโปรเจกต์ เขียนชื่ออิมเมจแทน ghcr.io/example/support-agent:1.0.0 ใน import-answers.yaml แล้วนำเข้าอีกครั้งด้วย --sync ซึ่งเขียนคำตอบใหม่ลงในฉบับร่างและ pull อีกครั้ง จากนั้นบิลด์:

Terminal window
docker build -t docs-assistant:local .
aggrega import support-agent.yaml --sync
aggrega build --release release.yaml

เมื่อใช้ docs-assistant:local เป็นคำตอบ การ sync ระบุค่าเดียวที่เปลี่ยนไว้ในบรรดาบรรทัดที่พิมพ์:

changed spec.components.supportagent.infra.image in release.yaml

จากนั้นตั้งคีย์ใน shell ของคุณและเริ่มสแตก:

Terminal window
export OPENAI_API_KEY='your OpenAI key'
docker compose -p docs-assistant -f dist/compose/docker-compose.yaml up -d --wait

-p ตั้งชื่อโปรเจกต์ ตามที่ขั้นตอนรันใน วิธีที่การนำเข้าทำงาน อธิบาย

ทดสอบ

คำขอด้านล่างไปถึงโปรแกรมที่อิมเมจของบทแนะนำนี้รัน: เอเจนต์เชิงประกาศหลังเซิร์ฟเวอร์ HTTP ขนาดเล็กบนพอร์ต 8000 ที่ตอบ POST /ask โปรแกรมของคุณกำหนดเส้นทางและการตอบกลับของตนเอง ส่งคำขอไปที่ http://127.0.0.1:8000 ซึ่งเป็นที่อยู่ที่ published_port เผยแพร่ เมื่อโปรแกรมฟังอยู่ ไม่กี่วินาทีหลังสแตกเริ่มทำงาน:

Terminal window
curl -sS -X POST http://127.0.0.1:8000/ask -H 'Content-Type: application/json' \
-d '{"question": "In one short sentence: what is Azure Container Apps?"}'
{"error": "the agent failed: ChatClientException: (\"<class 'agent_framework_openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key, and the same error repeated as the exception it wraps]"}

การรันตั้ง OPENAI_API_KEY เป็นตัวยึดตำแหน่ง การตอบกลับจึงเป็นการที่ OpenAI ปฏิเสธคีย์นั้น ซึ่งโปรแกรมส่งต่อมา คีย์ที่ OpenAI ปฏิเสธคือตัวยึดตำแหน่งนั้น แสดงแบบปิดบังบางส่วน =Env.OPENAI_API_KEY ของเอเจนต์เชิงประกาศจึงอ่านคีย์นั้นจากสภาพแวดล้อมที่บิลด์ส่งมอบ

หยุดสแตกด้วย:

Terminal window
docker compose -p docs-assistant -f dist/compose/docker-compose.yaml down

บน Kubernetes นำเข้าด้วย --target helm และ push อิมเมจไปยังรีจิสทรีที่คลัสเตอร์ของคุณ pull ได้ โดยระบุชื่อใน import-answers.yaml จากนั้นสร้าง Secret openai-api-key และนำบิลด์ไปใช้ ตามที่ขั้นตอนรันใน วิธีที่การนำเข้าทำงาน อธิบาย Deployment ของเอเจนต์ไม่มี Service จึงต้องส่งต่อพอร์ตภายในเครื่องไปยัง Deployment นั้น คำสั่งรันไปจนกว่าคุณจะหยุด:

Terminal window
kubectl port-forward deploy/supportagent 8000:8000
Forwarding from 127.0.0.1:8000 -> 8000
Forwarding from [::1]:8000 -> 8000

จากเทอร์มินัลอื่น ส่งคำขอเดียวกันไปยังพอร์ตที่ส่งต่อ:

Terminal window
curl -sS -X POST http://127.0.0.1:8000/ask -H 'Content-Type: application/json' \
-d '{"question": "In one short sentence: what is Azure Container Apps?"}'
{"error": "the agent failed: ChatClientException: (\"<class 'agent_framework_openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key, and the same error repeated as the exception it wraps]"}