تخطَّ إلى المحتوى
AggregaAggregaAggregaAggrega
اختر لغة: العربية
تُرجمت هذه الصفحة آليًا. اقرأ الأصل الإنجليزي.

استيراد مشروع CrewAI

يستورد هذا الشرح العملي إعلانات الوكلاء والمهام في مشروع CrewAI — طاقم من وكيلين يجيبان عن سؤال عميل بشأن خطط الدعم — ويبني الطاقم من أجل Docker Compose. ويصوغ الاستيراد مسودة كل ملف يقرؤه البناء: الوكيلين كليهما ونموذجهما، والمفتاح الذي يقدّمه كل منهما إلى النموذج على هيئة إشارة إلى متغير، وتحقيقات كل منها. ويطلب مرة واحدة القيمة الوحيدة التي لا يحملها أي إعلان، وهي صورة الحاوية التي يعمل بها برنامج الطاقم. كل ملف وكل كتلة من الإخراج أدناه مأخوذ من تشغيل فعلي؛ والإعلانات وكل مرحلة من الشرح العملي موجودة في المثال import-crewai، حيث يشغّل نص فحص برمجي الاستيراد مرة أخرى، ويقارن ما يكتبه وما يطبعه والكتل التي تقتبسها هذه الصفحة بالملفات المحفوظة هناك، ويتحقق مما كتبه الاستيراد ويبنيه.

صُغ مسودة المثال

يمكنك تشغيل هذا الاستيراد بالأوامر الواردة في هذه الصفحة، أو اجعل مساعد الذكاء الاصطناعي يشغّله نيابةً عنك.

اكتب المثال في مجلد جديد يحمل اسمه:

Terminal window
aggrega draft --example import-crewai

ثم يطبع الأوامر التي تُشغَّل بعد ذلك. يدخل الأول إلى المجلد الجديد؛ ويدخل الذي يليه، أدناه، إلى مجلد source الخاص به، الذي يحوي ما تستورده هذه الصفحة وهو المكان الذي يجري فيه الاستيراد:

Terminal window
cd import-crewai

مجلد مصدر المثال المسوَّد مفتوحًا في Visual Studio Code، يعرض تكوين وكلاء الطاقم مع باحث وكاتب.

المشروع

يحتفظ مشروع 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-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 الخاصة به. ولا تسمّي مساحة العمل أي مجلد كتالوج، لذا يقرأ الاستيراد كتالوج المكتبة القياسية من registry الذي يجلب منه مستورِده: لقطة موقَّعة من الكتالوج المطروح، يجلبها أول استيراد ويتحقق منها ويحفظها في ذاكرة التخزين المؤقت للمحتوى في مساحة العمل، ويسمّيها بملخّصها في ملف السجل الذي يكتبه الاستيراد بجوار مسوداته. وتقرأ مساحة العمل التي تسمّي مجلدات كتالوج خاصة بها — في 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 مخصصتان لبناء Kubernetes، مع --target helm: هناك يقرأ كل وكيل مفتاح OpenAI من Kubernetes Secret، والإجابة هي اسم Secret، openai-api-key، لا المفتاح أبدًا. أما بناء Docker Compose فيقرأ المفتاح من shell لديك بدلًا من ذلك، لذا لا يستخدم هذا الاستيراد تلك الإجابات. يصف ملف إجابات الاستيراد الملف والأسئلة وقواعد الإجابة عن السرّ.

يسرد aggrega import كل علامة يقبلها الأمر، ومنها --answers التي تسمّي ملف إجابات محفوظًا في مكان آخر.

انتقل إلى source:

Terminal window
cd source

شغّل الاستيراد

سمِّ دليل الطاقم. يقرأ الاستيراد الإعلانات الموجودة فيه ولا شيء غيرها:

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 المسوَّدة بجوار مشروع الطاقم، ويسرد إخراج 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 تقول إن المهام لا تُصاغ مسودةً كأي شيء: فالمهمة منطق يشغّله برنامج الطاقم.
  • السطر Pull complete هو الاستيراد وهو يجلب ما يعتمد عليه Release المسوَّد، كما يفعل aggrega pull، إلى release.lock، فتجتاز المسودات التحقق وتُبنى فورًا. وتحت --offline لا يجلب الاستيراد شيئًا ويسمّي الأمر 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 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 للباحث، الذي أُعلن verbose، و INFO للكاتب، الذي لم يُعلن ذلك. والوكيل الذي لا يعلن 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 ما لم تحدد غيره: الباحث على 8000 والكاتب على 8001، لأن خدمتين في Release واحد لا يمكنهما طرح المنفذ نفسه. ولا تسمّي الإعلانات متغيّرًا للمفتاح، لذا يقرؤه كل اتصال من ${OPENAI_API_KEY}، وهو المتغيّر الذي تقرؤه مكتبات العميل لدى OpenAI، على هيئة إشارة إلى متغيّر وليس قيمة أبدًا.

manifest.yaml — Recipe منصة Compose لكل نوع، والتحقيق الذي يكتب الإشارة إلى متغير المفتاح في ملف 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، ويبلّغ الإشعار بأن ورقة واحدة معلنة في كليهما. ولا يغيّر أي حكم.

خدمة الباحث في 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، وهما المتغيران اللذان يقرأ منهما CrewAI، والمفتاح في OPENAI_API_KEY. ويصل دوره وهدفه وخلفيته وخيار التفويض ومستوى السجل تحت الأسماء التي يمنحها Component CrewAI لها افتراضيًا، كي يقرأها برنامج الطاقم؛ وتسلّم كتلة inject: على المكوِّن نفسه أيًّا منها تحت الاسم الذي يقرؤه البرنامج بدلًا من ذلك. وتحتفظ كل قيمة صاغها الاستيراد مسودةً بكسر السطر الذي انتهى به إعلانها، فيكتبها الملف كتلة. ولا يحصل النموذج على خدمة خاصة به: فالوكلاء يصلون إلى OpenAI API على عنوانه الخاص. والمفتاح إشارة إلى متغير، تُملأ من shell لديك عند بدء مكدس Compose. وتطرح كل خدمة منفذها على 127.0.0.1 وحده: 8000 للباحث و 8001 للكاتب، يعيد كل منهما التوجيه إلى منفذ البرنامج 8000 داخل حاويته.

مع مساعد الذكاء الاصطناعي

يستطيع مساعد الذكاء الاصطناعي المُعَدّ بأدوات 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

مع تثبيت امتداد Aggrega في Visual Studio Code، افتح المجلد import-crewai/source في VS Code، حيث كتب الاستيراد مسوداته. ويحوي المجلد Release واحدًا، هو release.yaml المسوَّد، فيحدده المحرر لك، ويتحقق من المسودات مقابل ذلك Release أثناء تحريرك لها، ويعلّم ما يجده في الملف وفي لوحة Problems. ويرسم Aggrega: Show topology graph، في لوحة الأوامر، مكوِّنات Release والتوصيلات بينها. وتعمل Aggrega: Build و Aggrega: Preview build و Aggrega: Pull على Release نفسه، وكل منها زر أيضًا في لوحة Commands من عرض Aggrega في شريط النشاط؛ ويكتب Build ملفاته في dist/ الخاص بالمجلد. ويغطي استخدام Aggrega في Visual Studio Code الباقي.

شغِّله

تبني صورة الحاوية من المشروع، باستخدام Dockerfile خاص بك. ويشغّل Docker Compose أمر الصورة نفسها خدمةً لكل وكيل، لأن Recipe لا يضبط أيًّا منها، لذا يجب أن يستمر ذلك الأمر في العمل، ويجب أن يخدم الطلبات إن أردت الوصول إلى الطاقم. ويقرر برنامجك العنوان ومسار الطلب والاستجابة.

استخدم التشغيل أدناه صورةً كهذه: برنامج الطاقم بتخطيط CrewAI الكلاسيكي — crew.py يبني الطاقم من ملفَّي الإعلان كما قرأهما الاستيراد — وبوصفه أمر الصورة، خادم HTTP صغير خاص بالبرنامج على المنفذ 8000، يشغّل الطاقم مرة لكل طلب 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 لديك وابدأ مكدس Compose:

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

تسمّي -p المشروع، كما توضح خطوة التشغيل في كيف يعمل الاستيراد.

اختبره

يصل الطلب أدناه إلى البرنامج الذي تشغّله صورة هذا الشرح العملي: الطاقم خلف خادم HTTP صغير على المنفذ 8000، يجيب عن POST /kickoff. ويقرر برنامجك الخاص مساره واستجابته. أرسله إلى الباحث على http://127.0.0.1:8000، العنوان الذي يطرحه published_port، متى بدأ البرنامج الاستماع، بعد ثوانٍ قليلة من بدء مكدس Compose:

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 لها، يمرّره البرنامج. وقد وصل طلب الطاقم إلى OpenAI API بالمفتاح الذي سلّمه البناء. ويشغّل الوكيلان الصورة نفسها، لذا يمكن أن يذهب الطلب إلى أي منهما: ويجيب الكاتب بالطريقة نفسها على http://127.0.0.1:8001.

أوقف مكدس Compose بما يلي:

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

على Kubernetes، شغّل الاستيراد مع --target helm وأجرِ push لصورة الحاوية إلى registry يجلب منه عنقودك، مسمّيًا إياها في src/support_brief/import-answers.yaml. ثم أنشئ Secret openai-api-key وطبّق البناء، كما تصف خطوة التشغيل في كيف يعمل الاستيراد. ولا يملك Deployment كل وكيل أي Service، لذا أعد توجيه منفذ محلي إلى منفذ الباحث. ويستمر الأمر في العمل حتى توقفه:

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