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

นำเข้าโปรเจกต์ CrewAI

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

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

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

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

Terminal window
aggrega draft --example import-crewai

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

Terminal window
cd import-crewai

โฟลเดอร์ source ของตัวอย่างที่ร่างไว้ เปิดอยู่ใน Visual Studio Code แสดงการกำหนดค่าเอเจนต์ของ crew ที่มี researcher และ writer

โปรเจกต์

โปรเจกต์ CrewAI เก็บพฤติกรรมของ crew ไว้ในโปรแกรม และประกาศเอเจนต์กับงานในไฟล์การกำหนดค่า โปรเจกต์นี้เขียนสำหรับบทแนะนำนี้ ใช้เลย์เอาต์คลาสสิกของ CrewAI และการนำเข้าอ่านไฟล์การประกาศสองไฟล์ ใต้ src/support_brief/config/ การนำเข้าไม่อ่านโปรแกรม ได้แก่ crew.py ของโปรเจกต์คลาสสิกและเครื่องมือที่โปรแกรมกำหนด เลย ตัวอย่างจึงมีเฉพาะการประกาศ

agents.yaml ประกาศเอเจนต์สองตัว ทั้งสองใช้ gpt-4o-mini ของ OpenAI:

researcher:
role: >
Support plan researcher
goal: >
Find what each support plan of the company covers, and what it costs
backstory: >
You keep the company's support plans at your fingertips and answer from
them alone.
llm: openai/gpt-4o-mini
verbose: true
writer:
role: >
Support reply writer
goal: >
Turn the researcher's findings into a short, friendly reply to the customer
backstory: >
You write replies customers can act on, in plain words.
llm: openai/gpt-4o-mini

tasks.yaml มอบหมายงานหนึ่งงานให้แต่ละตัว:

research_task:
description: >
Find the support plans that answer the customer's question: {question}
expected_output: >
The plans that apply, each with what it covers and what it costs
agent: researcher
reply_task:
description: >
Write a reply to the customer's question from the researcher's findings
expected_output: >
A reply of at most five sentences
agent: writer

ที่รากของโปรเจกต์ .aggrega-config.yaml ทำให้โฟลเดอร์เป็นพื้นที่ทำงาน:

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

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

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

การประกาศระบุโมเดลของเอเจนต์แต่ละตัว ไม่ระบุอิมเมจที่โปรแกรมของ crew รันอยู่เลย คุณบิลด์อิมเมจนั้นจากโปรเจกต์ของคุณ การนำเข้าจึงถามหาอิมเมจนั้นหนึ่งครั้งต่อเอเจนต์แต่ละตัว บนเทอร์มินัลการนำเข้าถามหนึ่งคำถามต่อเอเจนต์ และเขียนคำตอบลงในฉบับร่างและในไฟล์คำตอบ import-answers.yaml ภายในไดเรกทอรีที่นำเข้า คือ src/support_brief/ การนำเข้าครั้งต่อไปจึงอ่านคำตอบจากที่นั่นและไม่ถามอะไร เมื่อไม่มีเทอร์มินัล — ในการรวมระบบอย่างต่อเนื่อง หรือผ่านท่อ — การนำเข้าไม่ถามอะไรเลย แต่เขียนไฟล์โดยปล่อยคีย์ว่าง แล้วหยุดโดยระบุชื่อไฟล์ ตัวอย่างมีไฟล์นี้อยู่แล้ว โดยให้เอเจนต์ทั้งสองตัวใช้อิมเมจเดียวกัน คือ ghcr.io/example/support-brief: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 CrewAI application code.
spec.components.researcher.infra.image: "ghcr.io/example/support-brief: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.researcher.uses.model.gpt-4o-mini.features.credential.infra.origin: "openai-api-key"
# Container image running the CrewAI application code.
spec.components.writer.infra.image: "ghcr.io/example/support-brief: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.writer.uses.model.gpt-4o-mini.features.credential.infra.origin: "openai-api-key"

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

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

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

Terminal window
cd source

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

ระบุไดเรกทอรีของ crew การนำเข้าอ่านการประกาศในไดเรกทอรีนั้นและไม่อ่านสิ่งอื่น:

Terminal window
aggrega import src/support_brief --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 crewai format, with drafted paths relative to <workspace>
info: the answers file <workspace>/src/support_brief/import-answers.yaml also answers spec.components.researcher.uses.model.gpt-4o-mini.features.credential.infra.origin in release.yaml, spec.components.writer.uses.model.gpt-4o-mini.features.credential.infra.origin in release.yaml, which these drafts do not leave empty; those answers are kept there and not applied
mapped researcher (agent) to core/ai-agent/crewai as a reference, NONE
mapped openai/gpt-4o-mini (llm) to core/ai-model/openai as a reference, NONE
mapped writer (agent) to core/ai-agent/crewai as a reference, NONE
made no choice for research_task (task)
made no choice for reply_task (task)
Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)

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

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

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

Aggregate, Release และ Manifest ชื่อ imported/support-brief: config/agents.yaml และ config/tasks.yaml ของโปรเจกต์ไม่ระบุชื่อ crew — ชื่ออยู่ในโปรแกรม ซึ่งการนำเข้าไม่อ่าน — การนำเข้าไดเรกทอรีของไฟล์เหล่านั้นจึงตั้งชื่อตามไดเรกทอรี คือ support_brief เขียนเป็นส่วนของชื่อ ภายใต้เนมสเปซที่การตั้งค่า target_namespace ของตัวนำเข้ากำหนด คือ imported เว้นแต่คุณตั้งค่าอื่น (การตั้งค่า)

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

# CrewAI declarations read:
# - config/agents.yaml
# - config/tasks.yaml
# Not read: the crew's program, which runs its agents and its tasks and defines its tools; it runs in the image the Release names for each agent.
# Tasks the crew's program runs, drafted as no Component:
# - research_task, assigned to researcher
# - reply_task, assigned to writer
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/support-brief
version: 0.1.0
description: Draft Aggregate imported from a source in the crewai format.
spec:
components:
researcher:
type: core/ai-agent/crewai
values:
role: "Support plan researcher\u000A"
goal: "Find what each support plan of the company covers, and what it costs\u000A"
backstory: "You keep the company's support plans at your fingertips and answer from them alone.\u000A"
allow_delegation: false
log_level: DEBUG
uses:
model:
gpt-4o-mini:
target: gpt-4o-mini
# For the compose target, the lines below declare credential on gpt-4o-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
writer:
type: core/ai-agent/crewai
values:
role: "Support reply writer\u000A"
goal: "Turn the researcher's findings into a short, friendly reply to the customer\u000A"
backstory: "You write replies customers can act on, in plain words.\u000A"
allow_delegation: false
log_level: INFO
uses:
model:
gpt-4o-mini:
target: gpt-4o-mini
# For the compose target, the lines below declare credential on gpt-4o-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 openai/gpt-4o-mini.
gpt-4o-mini:
type: core/ai-model/openai
values:
model: "gpt-4o-mini"

role, goal และ backstory นำมาตามที่ประกาศ รวมการขึ้นบรรทัดใหม่ที่บล็อกแบบพับแต่ละบล็อกลงท้าย log_level เป็น DEBUG สำหรับ researcher ซึ่งประกาศ verbose และ INFO สำหรับ writer ซึ่งไม่ได้ประกาศ เอเจนต์ที่ไม่ประกาศ allow_delegation ร่างด้วย false โมเดลเป็นบริการที่โฮสต์ไว้ Component ของเอเจนต์จึงปฏิเสธการเชื่อมต่อไปยังโมเดลนั้นที่ไม่มีข้อมูลรับรอง แต่ละการเชื่อมต่อประกาศหนึ่งรายการ ภายใต้คีย์ OPENAI_API_KEY

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

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/support-brief
# 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 crewai format.
spec:
aggregate: imported/support-brief
manifest: imported/support-brief
components:
researcher:
infra:
# Left for the Release, since the source cannot supply it: infra.image, the container image running the crew's program
image: "ghcr.io/example/support-brief: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-4o-mini:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential researcher presents to gpt-4o-mini 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}"
writer:
infra:
# Left for the Release, since the source cannot supply it: infra.image, the container image running the crew's program
image: "ghcr.io/example/support-brief: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: 8001
uses:
model:
gpt-4o-mini:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential writer presents to gpt-4o-mini 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}"
gpt-4o-mini: {}

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

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

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/support-brief
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/crewai: compose/crewai
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 และการแจ้งให้ทราบรายงานว่ามีค่าระดับใบหนึ่งค่าที่ประกาศไว้ทั้งสองที่ ซึ่งไม่เปลี่ยนคำตัดสิน

บริการของ researcher ใน dist/compose/docker-compose.yaml ส่วนของ writer ต่างกันเพียงชื่อ ค่าที่ตัวแปรของตนมี และพอร์ตที่เผยแพร่:

services:
researcher:
image: ghcr.io/example/support-brief:1.0.0
environment:
OPENAI_BASE_URL: https://api.openai.com/v1
MODEL: gpt-4o-mini
CREWAI_ALLOW_DELEGATION: "false"
CREWAI_BACKSTORY: |
You keep the company's support plans at your fingertips and answer from them alone.
CREWAI_GOAL: |
Find what each support plan of the company covers, and what it costs
CREWAI_LOG_LEVEL: DEBUG
CREWAI_ROLE: |
Support plan researcher
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_BASE_URL และ MODEL ซึ่งเป็นตัวแปรที่ CrewAI อ่านค่าเหล่านั้น และได้รับคีย์เป็น OPENAI_API_KEY role, goal, backstory สวิตช์การมอบหมาย และระดับบันทึกมาถึงภายใต้ชื่อที่ Component ของ CrewAI ตั้งให้โดยค่าเริ่มต้น เพื่อให้โปรแกรมของ crew อ่าน บล็อก inject: บนส่วนประกอบเองส่งมอบค่าเหล่านั้นค่าใดก็ได้ภายใต้ชื่อที่โปรแกรมอ่านแทน ค่าแต่ละค่าที่การนำเข้าร่างคงการขึ้นบรรทัดใหม่ที่การประกาศลงท้าย ไฟล์จึงเขียนเป็นบล็อก โมเดลไม่มีบริการของตนเอง: เอเจนต์เข้าถึง API ของ OpenAI ที่ที่อยู่ของ API นั้นเอง คีย์เป็นการอ้างอิงตัวแปรที่เติมจาก shell ของคุณเมื่อสแตกเริ่มทำงาน แต่ละบริการเผยแพร่พอร์ตบน 127.0.0.1 เท่านั้น: 8000 ของ researcher และ 8001 ของ writer ซึ่งแต่ละพอร์ตส่งต่อไปยังพอร์ต 8000 ของโปรแกรมภายในคอนเทนเนอร์

กับผู้ช่วย AI

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

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

เปิดใน VS Code

เปิดโฟลเดอร์ import-crewai/source ใน VS Code ที่ติดตั้ง ส่วนขยาย Aggrega สำหรับ Visual Studio 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 ของคุณเอง Docker Compose รันคำสั่งของอิมเมจเองเป็นบริการของเอเจนต์แต่ละตัว เพราะ Recipe ไม่ตั้งคำสั่งไว้ คำสั่งนั้นจึงต้องรันอยู่ต่อเนื่อง และต้องรับคำขอหากคุณต้องการเข้าถึง crew โปรแกรมของคุณกำหนดที่อยู่ เส้นทาง และการตอบกลับ

การรันด้านล่างใช้อิมเมจเช่นนั้น คือโปรแกรมของ crew ในโครงสร้างแบบคลาสสิกของ CrewAI — crew.py ที่สร้าง crew จากไฟล์การประกาศสองไฟล์ ตามที่การนำเข้าอ่าน — และคำสั่งของอิมเมจเป็นเซิร์ฟเวอร์ HTTP ขนาดเล็กของโปรแกรมเองบนพอร์ต 8000 ซึ่งรัน crew หนึ่งครั้งต่อ POST /kickoff แต่ละครั้ง บิลด์อิมเมจของคุณที่รากของโปรเจกต์ เขียนชื่ออิมเมจแทน ghcr.io/example/support-brief:1.0.0 สำหรับเอเจนต์ทั้งสองตัวใน src/support_brief/import-answers.yaml แล้วนำเข้าอีกครั้งด้วย --sync ซึ่งเขียนคำตอบใหม่ลงในฉบับร่างและ pull อีกครั้ง จากนั้นบิลด์:

Terminal window
docker build -t support-brief:local .
aggrega import src/support_brief --sync
aggrega build --release release.yaml

เมื่อให้ support-brief:local เป็นคำตอบทั้งสองข้อ การ sync ระบุค่าสองค่าที่เปลี่ยน ในบรรดาบรรทัดที่พิมพ์ออกมา:

changed spec.components.researcher.infra.image in release.yaml
changed spec.components.writer.infra.image in release.yaml

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

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

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

ทดสอบ

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

Terminal window
curl -sS -X POST http://127.0.0.1:8000/kickoff -H 'Content-Type: application/json' \
-d '{"question": "Which support plan covers a weekend outage, and what does it cost?"}'
{
"error": "the crew failed: AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key, and the error's type and code]"
}

การรันตั้ง OPENAI_API_KEY เป็นตัวยึดตำแหน่ง การตอบกลับจึงเป็นการที่ OpenAI ปฏิเสธคีย์นั้น ซึ่งโปรแกรมส่งต่อมา คำขอของ crew ไปถึง OpenAI API พร้อมคีย์ที่บิลด์ส่งมอบ เอเจนต์ทั้งสองตัวรันอิมเมจเดียวกัน คำขอจึงไปที่ตัวใดก็ได้: writer ตอบเหมือนกันที่ http://127.0.0.1:8001

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

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

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

Terminal window
kubectl port-forward deploy/researcher 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/kickoff -H 'Content-Type: application/json' \
-d '{"question": "Which support plan covers a weekend outage, and what does it cost?"}'
{
"error": "the crew failed: AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key, and the error's type and code]"
}