इसे छोड़कर कंटेंट पर जाएं
AggregaAggregaAggregaAggrega
भाषा चुने: हिन्दी
इस पेज का मशीन अनुवाद किया गया है। मूल अंग्रेज़ी पढ़ें।

एक LangGraph एप्लिकेशन इम्पोर्ट करें

यह वॉकथ्रू एक LangGraph एप्लिकेशन के कॉन्फ़िगरेशन को इम्पोर्ट करता है — एक ग्राफ़ जो ग्राहकों के उनके ऑर्डर से जुड़े प्रश्नों का उत्तर देता है — और एप्लिकेशन को Docker Compose के लिए बिल्ड करता है। इम्पोर्ट हर वह फ़ाइल ड्राफ़्ट करता है जिसे बिल्ड पढ़ता है: ग्राफ़, वह PostgreSQL डेटाबेस जिसमें उसका चेकपॉइंटर स्टेट रखता है, वह मॉडल जिसे वह कॉल करता है, पासवर्ड और कुंजी वेरिएबल संदर्भों के रूप में, और हर एक के रियलाइज़ेशन। यह उन दो मानों के बारे में एक बार पूछता है जो कोई कॉन्फ़िगरेशन नहीं रखता: वह मॉडल जिसे ग्राफ़ का कोड कॉल करता है, और वह इमेज जिसमें एप्लिकेशन चलता है। नीचे की हर फ़ाइल और आउटपुट का हर ब्लॉक एक वास्तविक रन से आता है; कॉन्फ़िगरेशन और वॉकथ्रू का हर चरण import-langgraph उदाहरण में है, जहाँ एक जाँच स्क्रिप्ट इम्पोर्ट को फिर से चलाती है, वह जो लिखता है, जो प्रिंट करता है और इस पेज में उद्धृत ब्लॉकों की तुलना वहाँ रखी फ़ाइलों से करती है, और इम्पोर्ट ने जो लिखा उसे वैलिडेट और बिल्ड करती है।

उदाहरण ड्राफ़्ट करें

आप यह इम्पोर्ट इस पेज के कमांडों से चला सकते हैं, या इसे अपने AI असिस्टेंट से चलवा सकते हैं।

उदाहरण को उसी के नाम वाले एक नए फ़ोल्डर में लिखें:

Terminal window
aggrega draft --example import-langgraph

फिर यह आगे चलाने के लिए कमांड प्रिंट करता है। पहला कमांड नए फ़ोल्डर में ले जाता है; उसके बाद वाला, नीचे दिया गया, उसके source फ़ोल्डर में ले जाता है, जिसमें वह है जिसे यह पेज इम्पोर्ट करता है और जहाँ इम्पोर्ट चलता है:

Terminal window
cd import-langgraph

तैयार किए गए उदाहरण का स्रोत फ़ोल्डर Visual Studio Code में खुला है, जो उसका LangGraph कॉन्फ़िगरेशन दिखाता है, जो एक ग्राफ़, support, का नाम देता है।

प्रोजेक्ट

एक LangGraph एप्लिकेशन अपने ग्राफ़ कोड में रखता है और उन्हें langgraph.json में घोषित करता है, जो LangGraph के कमांड-लाइन टूल की कॉन्फ़िगरेशन फ़ाइल है। यह फ़ाइल, जो इस वॉकथ्रू के लिए लिखी गई है, एक ग्राफ़, support, घोषित करती है, एप्लिकेशन के कोड में ग्राफ़ के इम्पोर्ट पाथ और एक विवरण के साथ:

{
"$schema": "https://langgra.ph/schema.json",
"dependencies": ["."],
"python_version": "3.12",
"graphs": {
"support": {
"path": "./src/support_agent/graph.py:graph",
"description": "Answers a question from a customer about their order, and hands it to a person when it cannot."
}
}
}

इम्पोर्ट langgraph.json पढ़ता है और एप्लिकेशन का कोड कभी नहीं, इसलिए उदाहरण में केवल कॉन्फ़िगरेशन है। उसके बगल में, एक .aggrega-config.yaml फ़ोल्डर को वर्कस्पेस बनाता है:

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

इम्पोर्ट कैटलॉग के LangGraph एजेंट, PostgreSQL और OpenAI मॉडल Components का संदर्भ देता है, और --target उसके Recipes से एक Manifest ड्राफ़्ट करता है। वर्कस्पेस किसी कैटलॉग फ़ोल्डर का नाम नहीं देता, इसलिए इम्पोर्ट स्टैंडर्ड लाइब्रेरी का कैटलॉग उसी रजिस्ट्री से पढ़ता है जिससे वह अपना इम्पोर्टर लाता है: प्रकाशित कैटलॉग का एक हस्ताक्षरित स्नैपशॉट, जिसे पहला इम्पोर्ट लाता है, सत्यापित करता है और वर्कस्पेस के कंटेंट कैश में रखता है, और जिसका नाम उसके डाइजेस्ट से उस रिकॉर्ड में दिया जाता है जिसे इम्पोर्ट अपने ड्राफ़्ट के बगल में लिखता है। जो वर्कस्पेस अपने कैटलॉग फ़ोल्डरों के नाम देता है — AGGREGA_CATALOG_DIRS में, या workspace.catalog_dirs के अंतर्गत — उन्हें पहले पढ़ता है, उनके पीछे प्रकाशित स्नैपशॉट के साथ।

इम्पोर्ट क्या पूछता है

एक LangGraph कॉन्फ़िगरेशन किसी मॉडल का नाम नहीं देता, क्योंकि उसे ग्राफ़ का कोड चुनता है, और किसी इमेज का भी नहीं, क्योंकि वह इमेज आप अपने प्रोजेक्ट से बनाते हैं। इसलिए इम्पोर्ट दोनों के बारे में पूछता है: उस मॉडल का नाम जिसे ग्राफ़ कॉल करता है, उस OpenAI मॉडल के लिए जिसे वह ड्राफ़्ट करता है, और वह इमेज जिसमें एप्लिकेशन चलता है। टर्मिनल पर वह पूछता है, और उत्तरों को ड्राफ़्ट में तथा उत्तर फ़ाइल import-answers.yaml में लिखता है, जो उस डायरेक्टरी के भीतर होती है जिसे वह इम्पोर्ट करता है — यहाँ प्रोजेक्ट का रूट, . — ताकि अगला इम्पोर्ट उन्हें वहीं से पढ़े और कुछ न पूछे। टर्मिनल के बिना — कंटीन्यूअस इंटीग्रेशन में, या किसी पाइप के ज़रिए — वह कुछ नहीं पूछता: वह फ़ाइल को खाली कुंजियों के साथ लिखता है, और रुक जाता है:

2 values the drafts leave empty are still owed, listed in the answers file <workspace>/import-answers.yaml: write each beside its key there, then run the import again

उदाहरण में यह फ़ाइल पहले से है, उत्तरों के साथ: ग्राफ़ OpenAI के gpt-4o-mini को कॉल करता है, और 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.
aggregate.yaml:
# Left for the author, since the configuration names no model: values.model, the name of the model
# core/ai-model/openai serves.
spec.components.model.values.model: "gpt-4o-mini"
release.yaml:
# Container image running the LangGraph application code. The Docker Compose Recipe runs the catalog's
# quickstart agent when it is unset.
spec.components.support.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.support.uses.checkpointer_db.postgres.features.credential.infra.origin: "support-db-password"
# 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.support.uses.model.model.features.credential.infra.origin: "openai-api-key"
# 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.postgres.features.password.infra.origin: "support-db-password"

तीन origin उत्तर Kubernetes के लिए बिल्ड के लिए हैं, --target helm के साथ: वहाँ डेटाबेस का पासवर्ड और OpenAI कुंजी Kubernetes Secrets से पढ़े जाते हैं, और हर उत्तर किसी Secret का नाम है — डेटाबेस का पासवर्ड, दोनों छोरों पर, support-db-password से, और कुंजी openai-api-key से — कभी पासवर्ड या कुंजी नहीं। Docker Compose के लिए बिल्ड इसके बजाय उन्हें आपके शेल से पढ़ता है, इसलिए यह इम्पोर्ट उन उत्तरों का उपयोग नहीं करता। इम्पोर्ट उत्तर फ़ाइल फ़ाइल, प्रश्नों और किसी सीक्रेट के उत्तर के नियमों का वर्णन करती है।

aggrega import उन सभी फ़्लैग की सूची देता है जिन्हें कमांड लेता है, और उनमें --answers भी है, जो कहीं और रखी गई उत्तर फ़ाइल का नाम देता है।

source में जाएँ:

Terminal window
cd source

इम्पोर्ट चलाएं

एप्लिकेशन की डायरेक्टरी का नाम दें। इम्पोर्ट उसकी langgraph.json पढ़ता है और उसकी कोई अन्य फ़ाइल नहीं:

Terminal window
aggrega import . --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 langgraph format, with drafted paths relative to <workspace>
info: the answers file <workspace>/import-answers.yaml also answers spec.components.postgres.features.password.infra.origin in release.yaml, spec.components.support.uses.checkpointer_db.postgres.features.credential.infra.origin in release.yaml, spec.components.support.uses.model.model.features.credential.infra.origin in release.yaml, which these drafts do not leave empty; those answers are kept there and not applied
mapped support (graph) to core/ai-agent/langgraph as a reference, NONE
mapped checkpointer (checkpointer) to core/datastore/postgres as a reference, NONE
mapped model (model) to core/ai-model/openai as a reference, NONE
Pull complete: <workspace>/release.lock (entities=10, source_artifacts=0, external_inputs=0)

एडिटर से चलाया गया इम्पोर्ट: ड्राफ़्ट किए गए Aggregate, Release और Manifest LangGraph कॉन्फ़िगरेशन के बगल में दिखाई देते हैं, Aggrega आउटपुट सूचीबद्ध करता है कि ग्राफ़, उसका चेकपॉइंटर और उसका मॉडल कैसे मैप किए गए और कौन-सी फ़ाइलें लिखी गईं, और एक नोटिफ़िकेशन बताता है कि इम्पोर्ट ने 3 फ़ाइलें ड्राफ़्ट कीं, जिन्हें langgraph के रूप में पहचाना गया।

  • info पंक्ति उन उत्तरों का नाम देती है जिनका Docker Compose ड्राफ़्ट उपयोग नहीं करते, और जो Kubernetes के लिए बिल्ड हेतु उत्तर फ़ाइल में रखे गए हैं।
  • mapped पंक्तियाँ बताती हैं कि ग्राफ़ स्टैंडर्ड लाइब्रेरी के LangGraph एजेंट core/ai-agent/langgraph का एक इंस्टेंस है; कि उसका चेकपॉइंटर, जहाँ LangGraph हर ग्राफ़ का स्टेट रखता है, core/datastore/postgres का एक इंस्टेंस है, क्योंकि कॉन्फ़िगरेशन किसी चेकपॉइंटर का नाम नहीं देता और तब LangGraph स्टेट PostgreSQL में रखता है; और कि वह मॉडल जिसे हर ग्राफ़ कॉल करता है, core/ai-model/openai का एक इंस्टेंस है। उनका स्तर NONE पढ़ता है: LangGraph इम्पोर्ट इन Components का संदर्भ इस आधार पर देता है कि कॉन्फ़िगरेशन क्या घोषित करता है, न कि हर एक को कैटलॉग से तौलकर। जिस कॉन्फ़िगरेशन का checkpointer.backend mongo है, उसे core/datastore/ferretdb के साथ ड्राफ़्ट किया जाता है, जो MongoDB का प्रोटोकॉल बोलता है, core/datastore/documentdb के ऊपर, दोनों वैसे वायर किए जाते हैं जैसे कैटलॉग का FerretDB Aggregate उन्हें वायर करता है, दोनों के लिए एक ही पासवर्ड के साथ।
  • Pull complete पंक्ति इम्पोर्ट द्वारा वह लाना है जिस पर ड्राफ़्ट किया गया Release निर्भर है, जैसे aggrega pull करता है, release.lock में, ताकि ड्राफ़्ट तुरंत वैलिडेट और बिल्ड हों। --offline के अंतर्गत इम्पोर्ट कुछ भी पुल नहीं करता और चलाने के लिए aggrega pull का नाम देता है।

यह क्या लिखता है

Aggregate, Release और Manifest का नाम imported/support रखा जाता है, उस एक ग्राफ़ के नाम पर जिसे langgraph.json सर्व करता है, support, क्योंकि किसी कॉन्फ़िगरेशन का अपना कोई नाम नहीं होता — कई ग्राफ़ सर्व करने वाले कॉन्फ़िगरेशन का नाम उसकी फ़ाइल के नाम पर रखा जाता है, या उसकी डायरेक्टरी के नाम पर जहाँ, जैसे यहाँ, इम्पोर्ट को उसकी डायरेक्टरी दी जाती है — उस नेमस्पेस के अंतर्गत जिसे इम्पोर्टर की target_namespace सेटिंग तय करती है, जो imported है जब तक आप कोई और सेट न करें (सेटिंग्स)।

aggregate.yaml — ग्राफ़, वह डेटाबेस जिसमें वह स्टेट रखता है और वह मॉडल जिसे वह कॉल करता है, हर कनेक्शन उस क्रेडेंशियल को घोषित करता है जो वह प्रस्तुत करता है, और फ़ाइल ऐसी टिप्पणियों से शुरू होती है जो बताती हैं कि क्या पढ़ा गया और क्या नहीं:

# LangGraph configurations read:
# - langgraph.json
# Not read: the application's code, which defines each graph; it runs in the image the Release names for each graph.
# Not carried, since they configure the server image langgraph build builds, and the image the Release names is the application's own: dependencies, python_version.
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/support
version: 0.1.0
description: Draft Aggregate imported from a source in the langgraph format.
spec:
components:
support:
type: core/ai-agent/langgraph
values:
graph_entrypoint: "./src/support_agent/graph.py:graph"
description: "Answers a question from a customer about their order, and hands it to a person when it cannot."
uses:
checkpointer_db:
postgres:
target: postgres
# For the compose target, the lines below declare credential on postgres: 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: POSTGRES_PASSWORD
model:
model:
target: model
# For the compose target, the lines below declare credential on model: 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 database the configuration's checkpointer keeps each graph's state in, PostgreSQL.
postgres:
type: core/datastore/postgres
features:
# For the compose target, the lines below declare password on postgres: 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.
password:
type: core/secret-value
values:
key: POSTGRES_PASSWORD
# The model every graph calls, which the configuration does not name.
model:
type: core/ai-model/openai
values:
# Left for the author, since the configuration names no model: values.model, the name of the model core/ai-model/openai serves.
model: "gpt-4o-mini"

graph_entrypoint ग्राफ़ का इम्पोर्ट पाथ है जैसा कॉन्फ़िगरेशन उसे लिखता है। उसका checkpointer_db कनेक्शन डेटाबेस से वायर किया गया है और उसका model कनेक्शन मॉडल से, जिसका नाम वह उत्तर है जिसे इम्पोर्ट ने import-answers.yaml से पढ़ा। recursion_limit नहीं लिखा गया है, इसलिए Component का डिफ़ॉल्ट, 25, लागू रहता है। डेटाबेस को एक पासवर्ड मिलता है, इसलिए PostgreSQL Recipe अपना कोई पासवर्ड नहीं लिखता, और ग्राफ़ डेटाबेस से अपने कनेक्शन पर वही पासवर्ड प्रस्तुत करता है।

release.yaml — एनवायरनमेंट, इमेज, प्रकाशित पोर्ट, और कुंजी तथा पासवर्ड कहाँ से आते हैं, साथ में ग्राफ़ के ऊपर टिप्पणियाँ जो बताती हैं कि उसकी इमेज क्या है और उसे क्या सौंपा जाता है:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/support
# 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 langgraph format.
spec:
aggregate: imported/support
manifest: imported/support
components:
# Each graph's image is the application's own, not the server image langgraph build builds: its code, with LangGraph installed.
# It is handed, for its code to read, the graph to run as LANGGRAPH_GRAPH_ENTRYPOINT, the model's name as OPENAI_MODEL, the checkpointer store's host and port as LANGGRAPH_CHECKPOINTER_HOST and LANGGRAPH_CHECKPOINTER_PORT, its user and database, where the store publishes them, as LANGGRAPH_CHECKPOINTER_USER and LANGGRAPH_CHECKPOINTER_DATABASE, and a password attached on the checkpointer_db connection as LANGGRAPH_CHECKPOINTER_PASSWORD.
# It is also handed the model's address as OPENAI_BASE_URL and a key attached on the model connection as OPENAI_API_KEY, which the OpenAI client library reads, and recursion_limit as LANGGRAPH_DEFAULT_RECURSION_LIMIT, which LangGraph reads.
# An inject: block on the graph's own instance, through an entry reading graph_entrypoint alone, replaces LANGGRAPH_GRAPH_ENTRYPOINT with the name it writes; one on the model connection replaces OPENAI_MODEL, and one on the checkpointer_db connection the store's host, port, user and database, with the names it writes.
support:
infra:
# Left for the Release, since the source cannot supply it: infra.image, the container image running the application
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:
checkpointer_db:
postgres:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential support presents to postgres on its checkpointer_db connection, the password of postgres (the configuration names no variable for it), read from the variable POSTGRES_PASSWORD, 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: "${POSTGRES_PASSWORD}"
model:
model:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential support presents to model on its model connection (the source names no variable for it, so it is read from the one OpenAI's client libraries read the API key from), 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}"
postgres:
features:
password:
type: core/secret-value
infra:
# Attached by reference, never as a value: the password of postgres (the configuration names no variable for it), read from the variable POSTGRES_PASSWORD, 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: "${POSTGRES_PASSWORD}"
model: {}

एनवायरनमेंट, development, एक डिफ़ॉल्ट है जिसे इम्पोर्ट इसलिए लिखता है क्योंकि कोई कॉन्फ़िगरेशन किसी एनवायरनमेंट का नाम नहीं देता; जहाँ Release कहीं और डिप्लॉय होता है, वहाँ इसे बदलें। इमेज वह उत्तर है जिसे इम्पोर्ट ने import-answers.yaml से पढ़ा। ग्राफ़ आपकी मशीन के लूपबैक पते पर, 8000 पर, प्रकाशित होता है, और उस पोर्ट पर फ़ॉरवर्ड करता है जिस पर उसका प्रोग्राम सुनता है, infra.port, जो 8000 है जब तक आप इसे सेट न करें। कुंजी और पासवर्ड वेरिएबल संदर्भ हैं, ${OPENAI_API_KEY} और ${POSTGRES_PASSWORD}, कभी मान नहीं।

manifest.yaml — हर टाइप की Compose Recipe, और वह रियलाइज़ेशन जो हर वेरिएबल संदर्भ को Compose फ़ाइल में ज्यों-का-त्यों लिखता है:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/support
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/langgraph: compose/langgraph
core/datastore/postgres: compose/postgres
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 लिखता है, जिसमें ग्राफ़ के लिए एक सेवा, डेटाबेस के लिए एक, और एक ऐसी सेवा होती है जो डेटाबेस की प्रतीक्षा करती है। ग्राफ़ की सेवा:

support:
image: ghcr.io/example/support-agent:1.0.0
environment:
LANGGRAPH_DEFAULT_RECURSION_LIMIT: "25"
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_MODEL: gpt-4o-mini
LANGGRAPH_CHECKPOINTER_HOST: postgres
LANGGRAPH_CHECKPOINTER_PORT: "5432"
LANGGRAPH_CHECKPOINTER_USER: appuser
LANGGRAPH_CHECKPOINTER_DATABASE: appdb
LANGGRAPH_GRAPH_ENTRYPOINT: ./src/support_agent/graph.py:graph
OPENAI_API_KEY: ${OPENAI_API_KEY}
LANGGRAPH_CHECKPOINTER_PASSWORD: ${POSTGRES_PASSWORD}
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
depends_on:
support--wait-for-store:
condition: service_completed_successfully
postgres:
condition: service_started

ग्राफ़ को मॉडल का पता, उसका नाम और उसकी कुंजी, डेटाबेस का होस्ट, पोर्ट, उपयोगकर्ता, डेटाबेस का नाम और पासवर्ड, और उसका अपना ग्राफ़ एंट्रीपॉइंट मिलता है। उपयोगकर्ता और डेटाबेस का नाम PostgreSQL Component के डिफ़ॉल्ट हैं, appuser और appdb, जिनके साथ नीचे की डेटाबेस सेवा बनाई जाती है; ग्राफ़ को ये इसलिए सौंपे जाते हैं क्योंकि PostgreSQL Recipe दोनों को प्रकाशित करती है, और जो स्टोर दोनों में से कोई प्रकाशित नहीं करता, जैसे Valkey, उसके लिए दोनों में से कोई नहीं सौंपा जाता। मॉडल का नाम, डेटाबेस का होस्ट, पोर्ट, उपयोगकर्ता और डेटाबेस का नाम और ग्राफ़ एंट्रीपॉइंट उन नामों के अंतर्गत पहुँचते हैं जिन्हें LangGraph Component डिफ़ॉल्ट रूप से देता है, और कनेक्शन पर, या अपने स्वयं के मानों के लिए स्वयं घटक पर, एक inject: ब्लॉक उन्हें उन नामों से बदल देता है जिन्हें आपका कोड पढ़ता है। मॉडल का पता, उसकी कुंजी और डेटाबेस का पासवर्ड वही रहते हैं जो ब्लॉक नाम देते हैं, और LANGGRAPH_DEFAULT_RECURSION_LIMIT भी, जिसे LangGraph स्वयं उस रन की चरण-सीमा के रूप में पढ़ता है जिसका कॉन्फ़िगरेशन कोई सीमा सेट नहीं करता। डेटाबेस की अपनी सेवा वही पासवर्ड लेती है:

postgres:
image: postgres:16
environment:
POSTGRES_USER: appuser
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: appdb
[… omitted: the labels the build writes on every service, the network, and a health check running PostgreSQL's pg_isready]

ग्राफ़ की सेवा तभी शुरू होती है जब तीसरी सेवा पूरी हो चुकी होती है। वह एक बार चलती है, ग्राफ़ की अपनी इमेज के बजाय कैटलॉग की क्विकस्टार्ट एजेंट इमेज में, और तब तक प्रतीक्षा करती है जब तक डेटाबेस का पता TCP कनेक्शन स्वीकार न करे, हर 2 s पर, अधिकतम 300 s तक, प्रयास करते हुए; तब तक कोई कनेक्शन न मिलने पर वह पते का नाम बताते हुए बाहर निकल जाती है, और ग्राफ़ शुरू नहीं होता। उसे डेटाबेस का होस्ट और पोर्ट सौंपा जाता है और कुछ नहीं:

support--wait-for-store:
image: hub.aggrega.ai/tools/quickstart-agent:1.0.1@sha256:a5f8dcfbb670d86a0cae0aadd2844bec93221a651238f8be3863873e261ee168
[… omitted: the command and the entrypoint, a bash loop that opens a connection to the address]
environment:
STORE_HOST: postgres
STORE_PORT: "5432"
[… omitted: the labels the build writes on every service, and the network]
restart: "no"

कुंजी और पासवर्ड वेरिएबल संदर्भ हैं, जो स्टैक शुरू होने पर आपके शेल से भरे जाते हैं। मॉडल को अपनी कोई सेवा नहीं मिलती: ग्राफ़ OpenAI API तक उसके अपने पते पर पहुँचता है। ग्राफ़ की सेवा अपना पोर्ट केवल 127.0.0.1 पर प्रकाशित करती है, और डेटाबेस के अपने पोर्ट तक स्टैक के नेटवर्क पर पहुँचा जाता है, बिना कुछ प्रकाशित किए।

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

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

केवल Aggrega टूल का उपयोग करें, और स्वयं कोई फ़ोल्डर न बनाएं। यदि Workspace फ़ोल्डर में अभी कोई `import-langgraph` फ़ोल्डर नहीं है, तो `draft` टूल को एक बार कॉल करें, `example` को `import-langgraph` पर सेट करके और बिना `dir` के: यह उदाहरण को एक नए `import-langgraph` फ़ोल्डर में लिखता है, जिसका `source` फ़ोल्डर वह रखता है जिसे यह पेज इम्पोर्ट करता है। फिर `import` टूल को कॉल करें, `workspace_root` को `import-langgraph/source` पर, `source` को `.` पर और `target` को `compose` पर सेट करके: यह जिन उत्तरों की उसे ज़रूरत है उन्हें `langgraph.json` के बगल में `import-answers.yaml` से पढ़ता है, अपने ड्राफ़्ट `import-langgraph/source` में लिखता है और उनकी ज़रूरत की चीज़ें पुल करता है। फिर `validate` टूल को कॉल करें, `workspace_root` को `import-langgraph/source` पर और `release` को `release.yaml` पर सेट करके, और `build` टूल को, `workspace_root` को `import-langgraph/source` पर, `release` को `release.yaml` पर और `write` को true पर सेट करके। मुझे बताएं कि बिल्ड ने कौन-सी फ़ाइलें लिखीं; वे `import-langgraph/source/dist/` के अंतर्गत हैं।

इसे VS Code में खोलें

Visual Studio Code के लिए Aggrega एक्सटेंशन इंस्टॉल होने पर, VS Code में import-langgraph/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 के साथ, बनाते हैं: ग्राफ़ का कोड, LangGraph इंस्टॉल किए हुए। Docker Compose ग्राफ़ की सेवा के रूप में इमेज का अपना कमांड चलाता है, क्योंकि Recipe कोई कमांड सेट नहीं करता, इसलिए उस कमांड को चलते रहना चाहिए, और यदि आप ग्राफ़ तक पहुँचना चाहते हैं तो अनुरोधों को सर्व करना चाहिए। वह ग्राफ़, मॉडल और डेटाबेस को ऊपर के वेरिएबल्स के ज़रिए ढूँढता है। पता, रूट और उत्तर आपका प्रोग्राम तय करता है।

नीचे के रन में ऐसी ही एक इमेज का उपयोग हुआ: उस पाथ पर ग्राफ़ जिसका langgraph.json नाम देता है, src/support_agent/graph.py, एक नोड जो उस मॉडल के ज़रिए उत्तर देता है जिसका OPENAI_MODEL नाम देता है, और, इमेज के कमांड के रूप में, पोर्ट 8000 पर प्रोग्राम का अपना एक छोटा HTTP सर्वर। इमेज अपनी वर्किंग डायरेक्टरी में प्रोजेक्ट का लेआउट रखती है, इसलिए वह पाथ जिसका LANGGRAPH_GRAPH_ENTRYPOINT नाम देता है, उसके सापेक्ष, ग्राफ़ को ढूँढ लेता है। सर्वर उस ग्राफ़ को लोड करता है, हर बातचीत का स्टेट LangGraph के PostgreSQL चेकपॉइंटर के ज़रिए डेटाबेस में रखता है, जिसे डेटाबेस के होस्ट, पोर्ट, उपयोगकर्ता, डेटाबेस के नाम और पासवर्ड के साथ खोला जाता है, हर एक उस LANGGRAPH_CHECKPOINTER_ वेरिएबल से पढ़ा जाता है जिसके अंतर्गत वह पहुँचता है, ताकि प्रोग्राम इनमें से कोई भी स्वयं न लिखे, और हर POST /threads/<thread>/runs के लिए ग्राफ़ को एक बार चलाता है। ग्राफ़ की सेवा तब शुरू होती है जब डेटाबेस कनेक्शन स्वीकार करने लगता है, इसलिए जो सर्वर शुरू होते ही चेकपॉइंटर खोलता है वह डेटाबेस को कनेक्शन स्वीकार करते हुए पाता है। अपनी इमेज प्रोजेक्ट के रूट पर बनाएं, import-answers.yaml में ghcr.io/example/support-agent:1.0.0 के स्थान पर उसका नाम लिखें, और --sync के साथ फिर से इम्पोर्ट करें, जो नया उत्तर ड्राफ़्ट में लिखता है और फिर से पुल करता है; फिर बिल्ड करें:

Terminal window
docker build -t order-support:local .
aggrega import . --sync
aggrega build --release release.yaml

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

Terminal window
export OPENAI_API_KEY='your OpenAI key'
export POSTGRES_PASSWORD='a password of your own'
docker compose -p order-support -f dist/compose/docker-compose.yaml up -d --wait

-p प्रोजेक्ट का नाम देता है, जैसा कि इम्पोर्ट कैसे चलता है का रन चरण समझाता है। --wait तब लौटता है जब डेटाबेस स्वस्थ होने की सूचना देता है, उसकी प्रतीक्षा पूरी हो चुकी होती है और ग्राफ़ की सेवा चल रही होती है।

इसे जाँचें

नीचे का अनुरोध उस प्रोग्राम तक पहुँचता है जिसे इस वॉकथ्रू की इमेज चलाती है: पोर्ट 8000 पर एक छोटे HTTP सर्वर के पीछे ग्राफ़, जो POST /threads/<thread>/runs का उत्तर देता है। आपका अपना प्रोग्राम अपना रूट और उत्तर स्वयं तय करता है। इसे http://127.0.0.1:8000 पर भेजें, वह पता जिसे published_port प्रकाशित करता है:

Terminal window
curl -sS -X POST http://127.0.0.1:8000/threads/order-1234/runs -H 'Content-Type: application/json' \
-d '{"message": "Where is my order 1234? It has not arrived yet."}'
{
"thread": "order-1234",
"error": "the run failed: OpenAIAuthenticationError: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key]"
}

रन ने OPENAI_API_KEY को एक प्लेसहोल्डर पर सेट किया, इसलिए उत्तर OpenAI द्वारा उसका अस्वीकरण है, जिसे प्रोग्राम ने आगे पहुँचाया। ग्राफ़ का अनुरोध बिल्ड द्वारा दी गई कुंजी के साथ OpenAI API तक पहुँचा, एक ऐसे प्रोग्राम से जिसने बिल्ड द्वारा दिए गए क्रेडेंशियल्स के साथ डेटाबेस में अपना चेकपॉइंटर खोला था।

स्टैक को इससे रोकें:

Terminal window
docker compose -p order-support -f dist/compose/docker-compose.yaml down -v

-v उस वॉल्यूम को हटा देता है जिसमें डेटाबेस अपना डेटा रखता है, और उसके साथ बातचीत भी।

Kubernetes पर, --target helm के साथ इम्पोर्ट करें और इमेज को ऐसी रजिस्ट्री में पुश करें जिससे आपका क्लस्टर पुल करता है, और import-answers.yaml में उसका नाम दें। फिर Secrets openai-api-key और support-db-password बनाएं और बिल्ड लागू करें, जैसा कि इम्पोर्ट कैसे चलता है का रन चरण वर्णन करता है। ग्राफ़ के Deployment का कोई Service नहीं है। उसका पॉड तब तक रीस्टार्ट होता रहता है जब तक डेटाबेस कनेक्शन स्वीकार न करे, क्योंकि प्रोग्राम शुरू होते ही अपना चेकपॉइंटर खोलता है। उस पर एक लोकल पोर्ट फ़ॉरवर्ड करें; कमांड तब तक चलता है जब तक आप उसे रोक न दें:

Terminal window
kubectl port-forward deploy/support 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/threads/order-1234/runs -H 'Content-Type: application/json' \
-d '{"message": "Where is my order 1234? It has not arrived yet."}'
{
"thread": "order-1234",
"error": "the run failed: OpenAIAuthenticationError: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key]"
}