Lewati ke konten
AggregaAggrega
Pilih Bahasa: Bahasa Indonesia
Halaman ini diterjemahkan oleh mesin. Baca versi asli dalam bahasa Inggris.

Mengimpor aplikasi LangGraph

Panduan langkah demi langkah ini mengimpor konfigurasi sebuah aplikasi LangGraph — satu graf yang menjawab pertanyaan pelanggan tentang pesanan mereka — dan membangun aplikasi tersebut untuk Docker Compose. Impor menyusun draf setiap file yang dibaca oleh build: graf, basis data PostgreSQL tempat checkpointer-nya menyimpan status, model yang dipanggilnya, kata sandi dan kunci sebagai referensi variabel, serta realisasi masing-masing. Impor menanyakan satu kali dua nilai yang tidak dimuat oleh konfigurasi apa pun: model yang dipanggil oleh kode graf, dan image tempat aplikasi berjalan. Setiap file dan setiap blok keluaran di bawah ini berasal dari eksekusi nyata; konfigurasi dan setiap tahap panduan ini ada di contoh import-langgraph, tempat sebuah skrip pemeriksaan menjalankan impor lagi, membandingkan apa yang ditulisnya, apa yang dicetaknya, dan blok-blok yang dikutip halaman ini dengan file yang disimpan di sana, serta memvalidasi dan membangun apa yang ditulis oleh impor.

Membuat contoh

Anda dapat menjalankan impor ini dengan perintah di halaman ini, atau meminta asisten AI Anda menjalankannya untuk Anda.

Tulis contoh ke folder baru yang dinamai sesuai contoh itu:

Terminal window
aggrega scaffold --example import-langgraph

Kemudian ia mencetak perintah yang dijalankan berikutnya. Perintah pertama berpindah ke folder baru; perintah sesudahnya, di bawah, berpindah ke folder source milik folder baru itu, yang berisi apa yang diimpor halaman ini dan merupakan tempat impor dijalankan:

Terminal window
cd import-langgraph

Folder source dari contoh hasil scaffold yang dibuka di Visual Studio Code, menampilkan konfigurasi LangGraph-nya, yang menyebutkan satu graf, support.

Proyek

Aplikasi LangGraph menyimpan grafnya di dalam kode dan mendeklarasikannya di langgraph.json, file konfigurasi alat baris perintah LangGraph. Aplikasi ini, yang ditulis untuk panduan ini, mendeklarasikan satu graf, support, melalui jalur impor graf di dalam kode aplikasi dan sebuah deskripsi:

{
"$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."
}
}
}

Impor membaca langgraph.json dan tidak pernah membaca kode aplikasi, sehingga contoh ini hanya berisi konfigurasi. Di sampingnya, sebuah .aggrega-config.yaml menjadikan folder tersebut sebuah ruang kerja:

# 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

Impor mereferensikan Components agen LangGraph, PostgreSQL, dan model OpenAI dari katalog, dan --target menyusun draf Manifest dari Recipes katalog tersebut. Ruang kerja tidak menyebutkan folder katalog apa pun, jadi impor membaca katalog pustaka standar dari registry tempat impor mengambil importer-nya: snapshot bertanda tangan dari katalog yang diterbitkan, yang diambil, diverifikasi, dan disimpan di cache konten ruang kerja oleh impor pertama, serta disebutkan melalui digest-nya dalam catatan yang ditulis impor di samping draf-drafnya. Ruang kerja yang menyebutkan folder katalognya sendiri — di AGGREGA_CATALOG_DIRS, atau di bawah workspace.catalog_dirs — mengimpor terhadap folder-folder itu sebagai gantinya.

Apa yang ditanyakan impor

Konfigurasi LangGraph tidak menyebutkan model, karena kode graf yang memilihnya, dan tidak menyebutkan image, karena Anda membangun image itu dari proyek Anda. Jadi impor menanyakan keduanya: nama model yang dipanggil graf, untuk model OpenAI yang didrafkannya, dan image tempat aplikasi berjalan. Di terminal, impor bertanya, lalu menulis jawabannya ke dalam draf dan ke dalam file jawaban, import-answers.yaml, di dalam direktori yang diimpornya — di sini root proyek, . — sehingga impor berikutnya membacanya dari sana dan tidak menanyakan apa pun. Tanpa terminal — dalam integrasi berkelanjutan, atau melalui pipe — impor tidak menanyakan apa pun: impor menulis file dengan kunci-kunci kosong, lalu berhenti:

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

Contoh ini sudah memuat file tersebut, lengkap dengan jawabannya: graf memanggil gpt-4o-mini dari OpenAI, dan ghcr.io/example/support-agent:1.0.0 mewakili image yang Anda bangun:

# 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"

Tiga jawaban origin ditujukan untuk build bagi Kubernetes, dengan --target helm: di sana kata sandi basis data dan kunci OpenAI dibaca dari Kubernetes Secret, dan setiap jawaban adalah nama sebuah Secret — kata sandi basis data dari support-db-password, di kedua ujung, dan kunci dari openai-api-key — tidak pernah kata sandi atau kunci itu sendiri. Build untuk Docker Compose membacanya dari shell Anda sebagai gantinya, sehingga impor ini tidak menggunakan jawaban-jawaban tersebut. File jawaban impor menjelaskan file tersebut, pertanyaan-pertanyaannya, dan aturan untuk jawaban sebuah rahasia.

aggrega import mencantumkan setiap flag yang diterima perintah ini, termasuk --answers, yang menyebutkan file jawaban yang disimpan di tempat lain.

Pindah ke source:

Terminal window
cd source

Menjalankan impor

Sebutkan direktori aplikasi. Impor membaca langgraph.json di dalamnya dan tidak membaca file lain apa pun di direktori tersebut:

Terminal window
aggrega import . --target compose

Pada keluaran standar, impor mencantumkan apa yang ditulisnya:

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

Pada galat standar, dengan <workspace> mewakili folder tempat Anda menjalankannya:

[… 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)

Impor yang dijalankan dari editor: Aggregate, Release, dan Manifest hasil draf muncul di samping konfigurasi LangGraph, output Aggrega mencantumkan bagaimana graf, checkpointer-nya, dan modelnya dipetakan serta file yang ditulis, dan sebuah notifikasi menyatakan bahwa impor membuat draf 3 file, dikenali sebagai langgraph.

  • Baris info menyebutkan jawaban yang tidak digunakan oleh draf Docker Compose, yang disimpan dalam file jawaban untuk build bagi Kubernetes.
  • Baris-baris mapped menyatakan bahwa graf tersebut adalah instans dari agen LangGraph milik pustaka standar, core/ai-agent/langgraph; bahwa checkpointer-nya, tempat LangGraph menyimpan status setiap graf, adalah instans dari core/datastore/postgres, karena konfigurasi tidak menyebutkan checkpointer apa pun sehingga LangGraph menyimpan status di PostgreSQL; dan bahwa model yang dipanggil setiap graf adalah instans dari core/ai-model/openai. Tingkatnya tertulis NONE: impor LangGraph mereferensikan Components ini berdasarkan apa yang dideklarasikan konfigurasi, bukan dengan menimbang masing-masing terhadap katalog. Konfigurasi yang checkpointer.backend-nya bernilai mongo didrafkan dengan core/datastore/ferretdb, yang menggunakan protokol MongoDB, di atas core/datastore/documentdb, keduanya dihubungkan sebagaimana Aggregate FerretDB milik katalog menghubungkannya, dengan satu kata sandi untuk keduanya.
  • Baris Pull complete adalah impor yang mengambil apa yang menjadi dependensi Release yang dirancang, seperti yang dilakukan aggrega pull, ke dalam release.lock, sehingga draf dapat langsung divalidasi dan di-build. Dengan --offline, impor tidak mengambil apa pun dan menyebutkan perintah aggrega pull yang perlu dijalankan.

Apa yang ditulisnya

Aggregate, Release, dan Manifest diberi nama imported/support, berdasarkan satu-satunya graf yang dilayani langgraph.json, support, karena konfigurasi tidak membawa nama sendiri — konfigurasi yang melayani beberapa graf dinamai berdasarkan filenya, atau berdasarkan direktorinya bila, seperti di sini, impor diberi direktorinya — di bawah namespace yang ditetapkan oleh pengaturan target_namespace milik pengimpor, yaitu imported kecuali Anda menetapkan yang lain (Pengaturan).

aggregate.yaml — graf, basis data tempat graf menyimpan statusnya, dan model yang dipanggilnya, dengan setiap koneksi mendeklarasikan kredensial yang disajikannya, diawali dengan komentar yang menyebutkan apa yang dibaca dan apa yang tidak:

# 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 adalah jalur impor graf sebagaimana ditulis oleh konfigurasi. Koneksi checkpointer_db-nya dihubungkan ke basis data dan koneksi model-nya ke model, yang namanya adalah jawaban yang dibaca impor dari import-answers.yaml. recursion_limit tidak ditulis, sehingga nilai bawaan Component, 25, tetap berlaku. Basis data mendapat kata sandi, sehingga Recipe PostgreSQL tidak menulis kata sandinya sendiri, dan graf menyajikan kata sandi yang sama pada koneksinya ke basis data.

release.yaml — lingkungan, image, port yang dipublikasikan, dan asal kunci serta kata sandi, dengan komentar di atas graf yang menyebutkan apa image-nya dan apa yang diberikan kepadanya:

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: {}

Lingkungan, development, adalah nilai bawaan yang ditulis impor karena tidak ada konfigurasi yang menyebutkannya; ubah nilai ini jika Release di-deploy ke tempat lain. Image adalah jawaban yang dibaca impor dari import-answers.yaml. Graf dipublikasikan di alamat loopback mesin Anda, pada 8000, dan diteruskan ke port tempat programnya mendengarkan, infra.port, yaitu 8000 kecuali Anda menetapkannya. Kunci dan kata sandi adalah referensi variabel, ${OPENAI_API_KEY} dan ${POSTGRES_PASSWORD}, tidak pernah berupa nilai.

manifest.yaml — Recipe Compose untuk setiap tipe, dan realisasi yang menulis setiap referensi variabel ke dalam file Compose persis seperti yang ditulis:

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 mencatat entitas katalog tempat Release diselesaikan, berdasarkan digest, dan .aggrega-import.json adalah catatan tentang apa yang ditulis impor, yang dibaca oleh aggrega import --sync berikutnya.

Validasi dan build

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

Release hasil draf yang dibuka di editor setelah divalidasi, dengan output Aggrega dan sebuah notifikasi yang sama-sama melaporkan tidak ada masalah yang ditemukan.

Build Release hasil draf: folder dist muncul di Explorer, output Aggrega mencantumkan file Docker Compose yang ditulis, dan sebuah notifikasi menyatakan bahwa 1 file telah ditulis.

Validasi mencetak:

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)

dan build, dengan <workspace> mewakili folder tempat Anda menjalankannya:

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

Baris notice hanya bersifat informatif: Feature rahasia menerima nilai origin miliknya dari values milik Aggregate atau infra milik Release, dan pemberitahuan itu melaporkan bahwa satu daun dideklarasikan di keduanya. Pemberitahuan ini tidak mengubah putusan apa pun.

Build menulis dist/compose/docker-compose.yaml, dengan satu layanan untuk graf, satu untuk basis data, dan satu yang menunggu basis data. Layanan graf:

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

Graf menerima alamat model, namanya, dan kuncinya, host, port, pengguna, nama, dan kata sandi basis data, serta titik masuk grafnya sendiri. Pengguna dan nama basis data adalah nilai bawaan Component PostgreSQL, appuser dan appdb, yang digunakan untuk membuat layanan basis data di bawah; graf menerimanya karena Recipe PostgreSQL memublikasikan keduanya, dan dengan penyimpanan yang tidak memublikasikan satu pun dari keduanya, seperti Valkey, graf tidak menerima satu pun. Nama model, host, port, pengguna, dan nama basis data, serta titik masuk graf tiba dengan nama-nama yang diberikan Component LangGraph secara bawaan, yang diganti oleh blok inject: pada koneksi, atau pada komponen itu sendiri untuk nilai-nilainya sendiri, dengan nama-nama yang dibaca kode Anda. Alamat model, kuncinya, dan kata sandi basis data tetap dengan nama yang disebutkan blok-blok tersebut, begitu pula LANGGRAPH_DEFAULT_RECURSION_LIMIT, yang dibaca LangGraph dengan sendirinya sebagai batas langkah suatu eksekusi yang konfigurasinya tidak menetapkan batas apa pun. Layanan basis data itu sendiri menerima kata sandi yang sama:

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]

Layanan graf baru dimulai setelah layanan ketiga selesai. Layanan ketiga berjalan sekali, di image agen quickstart milik katalog alih-alih di image graf itu sendiri, dan menunggu hingga alamat basis data menerima koneksi TCP, mencoba setiap 2 detik selama paling lama 300 detik; jika belum ada koneksi hingga saat itu, layanan ini keluar sambil menyebutkan alamatnya, dan graf tidak dimulai. Layanan ini menerima host dan port basis data, dan tidak ada yang lain:

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"

Kunci dan kata sandi adalah referensi variabel, yang diisi dari shell Anda saat stack dimulai. Model tidak mendapat layanan sendiri: graf menjangkau API OpenAI di alamat API itu sendiri. Layanan graf memublikasikan port-nya hanya di 127.0.0.1, dan port basis data itu sendiri dijangkau di jaringan stack, tanpa ada yang dipublikasikan.

Dengan asisten AI

Asisten AI yang disiapkan dengan alat-alat Aggrega dapat melakukan hal yang sama: tempelkan prompt ini ke dalamnya.

Gunakan hanya alat Aggrega, dan jangan membuat folder sendiri. Jika folder Workspace belum berisi folder `import-langgraph`, panggil alat `scaffold` sekali dengan `example` diatur ke `import-langgraph` dan tanpa `dir`: alat ini menulis contoh ke folder `import-langgraph` baru, yang folder `source`-nya berisi apa yang diimpor halaman ini. Lalu panggil alat `import` dengan `workspace_root` diatur ke `import-langgraph/source`, `source` diatur ke `.`, dan `target` diatur ke `compose`: alat ini membaca jawaban yang dibutuhkannya dari `import-answers.yaml` di samping `langgraph.json`, menulis drafnya ke `import-langgraph/source`, dan menarik apa yang dibutuhkan draf tersebut. Lalu panggil alat `validate` dengan `workspace_root` diatur ke `import-langgraph/source` dan `release` diatur ke `release.yaml`, serta alat `build` dengan `workspace_root` diatur ke `import-langgraph/source`, `release` diatur ke `release.yaml`, dan `write` diatur ke true. Beri tahu saya file mana yang ditulis build; file-file itu ada di bawah `import-langgraph/source/dist/`.

Membukanya di VS Code

Dengan ekstensi Aggrega untuk Visual Studio Code terpasang, buka folder import-langgraph/source di VS Code, tempat impor menulis drafnya. Folder ini berisi satu Release, yaitu release.yaml hasil draf, sehingga editor memilihnya untuk Anda, dan memeriksa draf terhadap Release tersebut saat Anda menyuntingnya, menandai temuannya di file dan di panel Problems. Aggrega: Show topology graph, di Command Palette, menggambar komponen Release dan koneksi di antaranya. Aggrega: Build, Aggrega: Preview build, dan Aggrega: Pull bekerja pada Release yang sama, dan masing-masing juga merupakan tombol di panel Commands pada tampilan Aggrega di activity bar; Build menulis file-filenya ke dist/ milik folder tersebut. Menggunakan Aggrega di Visual Studio Code membahas sisanya.

Menjalankannya

Anda membangun image dari proyek, dengan Dockerfile milik Anda sendiri: kode graf, dengan LangGraph terpasang. Docker Compose menjalankan perintah milik image itu sendiri sebagai layanan graf, karena Recipe tidak menetapkan perintah apa pun, sehingga perintah tersebut harus tetap berjalan, dan harus melayani permintaan jika Anda ingin menjangkau graf. Perintah itu menemukan graf, model, dan basis data melalui variabel di atas. Program Anda yang menentukan alamat, rute, dan balasannya.

Eksekusi di bawah ini menggunakan image seperti itu: graf di jalur yang disebutkan langgraph.json, src/support_agent/graph.py, satu node yang menjawab melalui model yang disebutkan OPENAI_MODEL, dan, sebagai perintah image, server HTTP kecil milik program itu sendiri di port 8000. Image mempertahankan tata letak proyek di direktori kerjanya, sehingga jalur yang disebutkan LANGGRAPH_GRAPH_ENTRYPOINT, relatif terhadap direktori itu, menemukan graf. Server memuat graf tersebut, menyimpan status setiap percakapan di basis data melalui checkpointer PostgreSQL milik LangGraph, yang dibuka dengan host, port, pengguna, nama, dan kata sandi basis data, masing-masing dibaca dari variabel LANGGRAPH_CHECKPOINTER_ tempat nilai itu tiba, sehingga program tidak menuliskan satu pun sendiri, lalu menjalankan graf satu kali untuk setiap POST /threads/<thread>/runs. Layanan graf dimulai begitu basis data menerima koneksi, sehingga server yang membuka checkpointer saat dimulai mendapati basis data sudah menerima koneksi. Bangun image Anda di root proyek, tulis namanya sebagai pengganti ghcr.io/example/support-agent:1.0.0 di import-answers.yaml, lalu impor lagi dengan --sync, yang menulis jawaban baru ke dalam draf dan melakukan pull lagi; kemudian lakukan build:

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

Kemudian tetapkan kunci dan kata sandi basis data di shell Anda, lalu mulai stack:

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 menamai proyek, seperti yang dijelaskan langkah menjalankan di Cara impor berjalan. --wait kembali setelah database melaporkan status sehat, penantian untuknya selesai, dan layanan graf berjalan.

Mengujinya

Permintaan di bawah ini mencapai program yang dijalankan image panduan ini: graf di balik server HTTP kecil pada port 8000, yang menjawab POST /threads/<thread>/runs. Program Anda sendiri menentukan rute dan balasannya sendiri. Kirimkan ke http://127.0.0.1:8000, alamat yang dipublikasikan 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]"
}

Eksekusi tersebut menetapkan OPENAI_API_KEY ke nilai pengganti, sehingga balasannya adalah penolakan OpenAI terhadap kunci itu, yang diteruskan oleh program. Permintaan graf mencapai API OpenAI dengan kunci yang dikirimkan build, dari program yang telah membuka checkpointer-nya di basis data dengan kredensial yang dikirimkan build.

Hentikan stack dengan:

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

-v menghapus volume tempat basis data menyimpan datanya, beserta percakapan-percakapannya.

Di Kubernetes, impor dengan --target helm dan push image ke registri tempat kluster Anda menarik image, dengan menyebutkan namanya di import-answers.yaml. Lalu buat Secret openai-api-key dan support-db-password lalu terapkan build, seperti yang dijelaskan langkah eksekusi di Cara impor berjalan. Deployment graf tidak memiliki Service. Pod-nya dimulai ulang sampai basis data menerima koneksi, karena program membuka checkpointer-nya saat dimulai. Teruskan sebuah port lokal ke sana; perintah berjalan sampai Anda menghentikannya:

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

Dari terminal lain, kirim permintaan yang sama ke port yang diteruskan:

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