इसे छोड़कर कंटेंट पर जाएं
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 मॉडल और अपने Microsoft Learn MCP टूल के साथ दिख रहा है।

प्रोजेक्ट

Agent Framework पर बना एप्लिकेशन किसी डिक्लेरेटिव एजेंट से एक एजेंट लोड कर सकता है: kind Prompt का एक YAML दस्तावेज़, जो एजेंट के मॉडल, उसके निर्देशों और उसके टूल का नाम देता है। यह दस्तावेज़, जो इस वॉकथ्रू के लिए लिखा गया है, OpenAI के gpt-4.1-mini और उस 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

इम्पोर्ट कैटलॉग के Agent Framework एजेंट और OpenAI मॉडल Components का संदर्भ देता है, और --target उसके Recipes से एक Manifest ड्राफ़्ट करता है। वर्कस्पेस किसी कैटलॉग फ़ोल्डर का नाम नहीं देता, इसलिए इम्पोर्ट स्टैंडर्ड लाइब्रेरी का कैटलॉग उसी रजिस्ट्री से पढ़ता है जिससे वह अपना इम्पोर्टर लाता है: प्रकाशित कैटलॉग का एक हस्ताक्षरित स्नैपशॉट, जिसे पहला इम्पोर्ट लाता है, सत्यापित करता है और वर्कस्पेस के कंटेंट कैश में रखता है, और जिसका नाम उसके डाइजेस्ट से उस रिकॉर्ड में दिया जाता है जिसे इम्पोर्ट अपने ड्राफ़्ट के बगल में लिखता है। जो वर्कस्पेस अपने स्वयं के कैटलॉग फ़ोल्डरों का नाम देता है — 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 के बगल में, लिखता है, ताकि अगला इम्पोर्ट उसे वहीं से पढ़े और कुछ न पूछे। टर्मिनल के बिना — कंटीन्यूअस इंटीग्रेशन में, या किसी पाइप के माध्यम से — यह कुछ नहीं पूछता: यह फ़ाइल को खाली कुंजी के साथ लिखता है, और फ़ाइल का नाम बताते हुए रुक जाता है। उदाहरण में यह फ़ाइल पहले से है, जिसमें इमेज का उत्तर दिया गया है, 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 के लिए बिल्ड इसके बजाय कुंजी आपके शेल से पढ़ता है, इसलिए यह इम्पोर्ट उस उत्तर का उपयोग नहीं करता। इम्पोर्ट उत्तर फ़ाइल फ़ाइल, प्रश्नों और किसी सीक्रेट के उत्तर के नियमों का वर्णन करती है।

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 के अंतर्गत इम्पोर्ट कुछ भी पुल नहीं करता और चलाने के लिए 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 पर पहुँचता है, इसलिए वह प्रोवाइडर से पहुँच योग्य होना चाहिए। निर्देश, मॉडल के अनुरोधों के विकल्प, और सर्वर का विवरण, अनुमोदन मोड और अनुमत टूल डिक्लेरेटिव एजेंट में रहते हैं, जिसे एप्लिकेशन पढ़ता है; टिप्पणियाँ हर एक का नाम देती हैं। OpenAI का API एक होस्टेड सेवा है, इसलिए एजेंट का Component उससे ऐसे कनेक्शन को अस्वीकार करता है जो कोई क्रेडेंशियल नहीं रखता; कनेक्शन एक क्रेडेंशियल घोषित करता है, कुंजी 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 का बिल्ड: Explorer में एक dist फ़ोल्डर दिखता है, Aggrega आउटपुट लिखी गई Docker Compose फ़ाइल की सूची देता है, और एक नोटिफ़िकेशन बताता है कि 1 फ़ाइल लिखी गई।

वैलिडेशन प्रिंट करता है:

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 Aggregate के values से या Release के infra से स्वीकार करता है, और नोटिस बताता है कि एक लीफ़ दोनों में घोषित है। यह कोई निर्णय नहीं बदलती।

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

एप्लिकेशन मॉडल का पता, उसका नाम और उसकी कुंजी उन वेरिएबल में प्राप्त करता है जिन्हें Agent Framework के OpenAI क्लाइंट पढ़ते हैं, इसलिए डिक्लेरेटिव एजेंट का =Env.OPENAI_API_KEY वह कुंजी पढ़ता है जिसे Release ने अटैच किया, जहाँ एप्लिकेशन उसे उस तरह लोड करता है जैसा प्रोजेक्ट बताता है। कोई वेरिएबल MCP सर्वर का पता नहीं रखता, जिस तक प्रोवाइडर पहुँचता है। मॉडल को अपनी कोई सेवा नहीं मिलती: एजेंट OpenAI API तक उसके अपने पते पर पहुँचता है। कुंजी एक वेरिएबल संदर्भ है, जो स्टैक शुरू होने पर आपके शेल से भरा जाता है। सेवा अपना पोर्ट केवल 127.0.0.1 पर प्रकाशित करती है।

AI असिस्टेंट के साथ

Aggrega के टूल के साथ सेट अप किया गया AI असिस्टेंट भी यही कर सकता है: यह प्रॉम्प्ट उसमें पेस्ट करें।

केवल Aggrega टूल का उपयोग करें, और स्वयं कोई फ़ोल्डर न बनाएं। यदि Workspace फ़ोल्डर में अभी कोई `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` पर सेट करके: यह जिन उत्तरों की आवश्यकता है उन्हें `support-agent.yaml` के बगल में `import-answers.yaml` से पढ़ता है, अपने ड्राफ़्ट `import-agent-framework/source` में लिखता है और जो उन्हें चाहिए उसे पुल करता है। फिर `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 में खोलें

Visual Studio Code के लिए Aggrega एक्सटेंशन इंस्टॉल होने पर, VS Code में फ़ोल्डर import-agent-framework/source खोलें, जहाँ इम्पोर्ट ने अपने ड्राफ़्ट लिखे। फ़ोल्डर में एक Release है, ड्राफ़्ट किया गया release.yaml, इसलिए एडिटर उसे आपके लिए चुन लेता है, और जब आप ड्राफ़्ट संपादित करते हैं तो वह उन्हें उस Release के विरुद्ध जाँचता है, और जो कुछ उसे मिलता है उसे फ़ाइल में और Problems पैनल में चिह्नित करता है। कमांड पैलेट में Aggrega: Show topology graph Release के घटकों और उनके बीच के कनेक्शनों को बनाता है। Aggrega: Build, Aggrega: Preview build और Aggrega: Pull उसी Release पर काम करते हैं, और हर एक एक्टिविटी बार में Aggrega व्यू के Commands पैनल पर एक बटन भी है; Build अपनी फ़ाइलें फ़ोल्डर के dist/ में लिखता है। बाकी सब Visual Studio Code में Aggrega का उपयोग करें में है।

इसे चलाएं

आप इमेज प्रोजेक्ट से, अपने स्वयं के Dockerfile के साथ, बिल्ड करते हैं: एप्लिकेशन का कोड, जिसमें Agent Framework इंस्टॉल हो और डिक्लेरेटिव एजेंट अंदर हो। Docker Compose इमेज के अपने कमांड को एजेंट की सेवा के रूप में चलाता है, क्योंकि Recipe कोई कमांड निर्धारित नहीं करता, इसलिए वह कमांड चलता रहना चाहिए, और यदि आप एजेंट तक पहुँचना चाहते हैं तो उसे अनुरोधों का उत्तर देना चाहिए। पता, रूट और जवाब आपका प्रोग्राम तय करता है।

नीचे का रन ऐसी ही एक इमेज के साथ हुआ: Agent Framework के agent-framework-core, agent-framework-openai और agent-framework-declarative पैकेज के साथ Python, एक .NET रनटाइम — इमेज ने DOTNET_ROOT को उसकी डायरेक्टरी पर और DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 सेट किया — support-agent.yaml, और, इमेज के कमांड के रूप में, पोर्ट 8000 पर प्रोग्राम का अपना एक छोटा HTTP सर्वर। सर्वर डिक्लेरेटिव एजेंट को AgentFactory(safe_mode=False) के साथ लोड करता है, इसलिए उसका =Env.OPENAI_API_KEY वह कुंजी पढ़ता है जिसे बिल्ड पहुँचाता है, और हर POST /ask के लिए एजेंट को एक बार चलाता है। अपनी इमेज प्रोजेक्ट के रूट पर बिल्ड करें, import-answers.yaml में ghcr.io/example/support-agent:1.0.0 के स्थान पर उसका नाम लिखें, और --sync के साथ फिर से इम्पोर्ट करें, जो नया उत्तर ड्राफ़्ट में लिखता है और फिर से पुल करता है; फिर बिल्ड करें:

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

उत्तर के रूप में docs-assistant:local होने पर, सिंक अपने द्वारा प्रिंट की गई पंक्तियों में उस एक मान का नाम देता है जिसे उसने बदला:

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

फिर अपने शेल में कुंजी सेट करें और स्टैक शुरू करें:

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

-p प्रोजेक्ट का नाम देता है, जैसा इम्पोर्ट कैसे चलता है का रन चरण बताता है।

इसे जाँचें

नीचे का अनुरोध उस प्रोग्राम तक पहुँचता है जिसे इस वॉकथ्रू की इमेज चलाती है: पोर्ट 8000 पर एक छोटे HTTP सर्वर के पीछे डिक्लेरेटिव एजेंट, जो 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 के साथ इम्पोर्ट करें और इमेज को ऐसी रजिस्ट्री पर पुश करें जिससे आपका क्लस्टर पुल करता है, और import-answers.yaml में उसका नाम दें। फिर Secret openai-api-key बनाएं और बिल्ड लागू करें, जैसा इम्पोर्ट कैसे चलता है का रन चरण बताता है। एजेंट के Deployment का कोई Service नहीं है, इसलिए एक लोकल पोर्ट को उस पर फ़ॉरवर्ड करें। कमांड तब तक चलता है जब तक आप उसे रोक न दें:

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]"}