นำเข้าโปรเจกต์ CrewAI
บท
ร่างตัวอย่าง
คุณ
เขียน
aggrega draft --example import-crewaiจากsource ซึ่ง
cd import-crewai
โปรเจกต์
โปรเจกต์ 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-minitasks.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การนำ--target ร่าง Manifest จาก Recipes ของAGGREGA_CATALOG_DIRS หรือworkspace.catalog_dirs — อ่าน
สิ่งที่การนำเข้าถาม
การ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 สอง--target helm ซึ่งopenai-api-key ไม่ใช่
aggrega import ระบุ--answers ซึ่ง
เปลี่ยนsource:
cd sourceรันการนำเข้า
ระบุ
aggrega import src/support_brief --target composeที่
wrote aggregate.yamlwrote release.yamlwrote manifest.yamlwrote .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 appliedmapped researcher (agent) to core/ai-agent/crewai as a reference, NONEmapped openai/gpt-4o-mini (llm) to core/ai-model/openai as a reference, NONEmapped writer (agent) to core/ai-agent/crewai as a reference, NONEmade 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)
- บรรทัด
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 ของ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 writerapiVersion: aggrega.ai/v1beta1kind: Aggregatemetadata: 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 โมเดลOPENAI_API_KEY
release.yaml — สภาพ
apiVersion: aggrega.ai/v1beta1kind: Releasemetadata: 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 เป็นimport-answers.yaml เอเจนต์infra.port ซึ่ง${OPENAI_API_KEY} ซึ่ง
manifest.yaml — Compose Recipe ของ
apiVersion: aggrega.ai/v1beta1kind: Manifestmetadata: name: imported/support-brief version: 0.1.0spec: mappings: components: type: core/ai-agent/crewai: compose/crewai core/ai-model/openai: compose/openai features: type: core/secret-value: compose/dotenv-secretrelease.lock บันทึก.aggrega-import.json เป็นaggrega import --sync ครั้ง
ตรวจสอบความถูกต้องและบิลด์
aggrega validate --release release.yamlaggrega build --release release.yaml

การ
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 เป็นorigin จาก values ของ Aggregate หรือ infra ของ Release และ
บริการdist/compose/docker-compose.yaml ส่วน
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 ซึ่งOPENAI_API_KEY role, goal, backstory สวิตช์inject: บน
กับผู้ช่วย AI
ผู้
ใช้เฉพาะเครื่องมือของ 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 ที่release.yaml ที่dist/ ของ
วิธีรัน
คุณ
การcrew.py ที่POST /kickoff แต่ละghcr.io/example/support-brief:1.0.0 สำหรับsrc/support_brief/import-answers.yaml แล้ว--sync ซึ่ง
docker build -t support-brief:local .aggrega import src/support_brief --syncaggrega build --release release.yamlเมื่อsupport-brief:local เป็น
changed spec.components.researcher.infra.image in release.yamlchanged spec.components.writer.infra.image in release.yamlจาก
export OPENAI_API_KEY='your OpenAI key'docker compose -p support-brief -f dist/compose/docker-compose.yaml up -d --wait-p ตั้ง
ทดสอบ
คำขอPOST /kickoff โปรแกรมpublished_port เผย
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 เป็น
หยุด
docker compose -p support-brief -f dist/compose/docker-compose.yaml downบน Kubernetes นำ--target helm และ push อิมเมจsrc/support_brief/import-answers.yaml จากopenai-api-key และ
kubectl port-forward deploy/researcher 8000:8000Forwarding from 127.0.0.1:8000 -> 8000Forwarding from [::1]:8000 -> 8000จาก
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]"}