mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-05 17:22:36 +00:00
added docs
This commit is contained in:
@@ -157,6 +157,43 @@ class ResearchFlow(Flow):
|
||||
|
||||
انظر [وثائق التدفقات](/concepts/flows) لمزيد من المعلومات حول الذاكرة في التدفقات.
|
||||
|
||||
## تخصيص مطالبات الذاكرة (`MemoryPromptConfig`)
|
||||
|
||||
يمكنك استبدال تعليمات نموذج اللغة في كل خطوة من تحليل الذاكرة (نفس فكرة ضبط مطالبات التخطيط). مرّر كائن `MemoryPromptConfig` كوسيط `memory_prompt` إلى `Memory`. عيّن الحقول التي تحتاجها فقط؛ تبقى الخطوات الأخرى على القيم الافتراضية المضمّنة في `translations/en.json` تحت المفتاح `memory` (أسماء الحقول تطابق مفاتيح JSON).
|
||||
|
||||
```python
|
||||
from crewai import Memory, MemoryPromptConfig
|
||||
|
||||
memory = Memory(
|
||||
llm="gpt-4o-mini",
|
||||
memory_prompt=MemoryPromptConfig(
|
||||
save_system="...", # اختياري
|
||||
query_user="...", # اختياري
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
يمكنك أيضًا تمرير `memory_prompt` إلى دوال مساعدة في `crewai.memory.analyze` (مثل `extract_memories_from_content`) عند استدعائها مباشرة.
|
||||
|
||||
### تأثير كل زوج من المطالبات
|
||||
|
||||
| الحقول | متى يعمل | ماذا يؤثر |
|
||||
| --- | --- | --- |
|
||||
| `save_system` / `save_user` | عند الحفظ (`analyze_for_save`) | `suggested_scope` و`categories` و`importance` و`extracted_metadata` المستنتجة قبل التخزين والتضمين. |
|
||||
| `query_system` / `query_user` | عند تحليل استعلام الاسترجاع (`analyze_query`) | `keywords` و`suggested_scopes` و`complexity` و`recall_queries` و`time_filter`، ما يوجّه البحث المتجهي وعمق الاسترجاع. |
|
||||
| `extract_memories_system` / `extract_memories_user` | `extract_memories_from_content` / `Memory.extract_memories` | كيفية تقسيم النص الخام إلى جمل ذاكرة منفصلة (لا يزال التخزين عبر `remember()`). |
|
||||
| `consolidation_system` / `consolidation_user` | عندما يكون المحتوى الجديد قريبًا دلاليًا من سجلات موجودة (`analyze_for_consolidation`) | الإبقاء على الصفوف أو تحديثها أو حذفها، وما إذا كان يُدرج المحتوى الجديد كذاكرة مستقلة. |
|
||||
|
||||
### العناصر النائبة (placeholders)
|
||||
|
||||
سلاسل **النظام (system)** تُرسل كما هي. سلاسل **المستخدم (user)** تُملأ بـ `str.format` في بايثون. يجب أن تتضمن قوالب المستخدم المخصصة نفس أسماء العناصر النائبة الافتراضية وإلا يفشل التنسيق.
|
||||
|
||||
| حقل المستخدم | عناصر نائبة مطلوبة |
|
||||
| --- | --- |
|
||||
| `save_user` | `{content}`، `{existing_scopes}`، `{existing_categories}` |
|
||||
| `query_user` | `{query}`، `{available_scopes}`، `{scope_desc}` |
|
||||
| `extract_memories_user` | `{content}` |
|
||||
| `consolidation_user` | `{new_content}`، `{records_summary}` |
|
||||
|
||||
## النطاقات الهرمية
|
||||
|
||||
|
||||
@@ -157,6 +157,43 @@ class ResearchFlow(Flow):
|
||||
|
||||
See the [Flows documentation](/concepts/flows) for more on memory in Flows.
|
||||
|
||||
## Customizing memory prompts (`MemoryPromptConfig`)
|
||||
|
||||
Override the LLM instructions used at each memory analysis step (same idea as tuning planning prompts). Pass a `MemoryPromptConfig` as `memory_prompt` on `Memory`. Only set the fields you need; every other step keeps the bundled defaults from the library’s `translations/en.json` under the `memory` key (field names match those JSON keys).
|
||||
|
||||
```python
|
||||
from crewai import Memory, MemoryPromptConfig
|
||||
|
||||
memory = Memory(
|
||||
llm="gpt-4o-mini",
|
||||
memory_prompt=MemoryPromptConfig(
|
||||
save_system="...", # optional
|
||||
query_user="...", # optional
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
You can also pass `memory_prompt` into helpers in `crewai.memory.analyze` (for example `extract_memories_from_content`) when you call them directly.
|
||||
|
||||
### What each prompt pair affects
|
||||
|
||||
| Fields | When it runs | What it influences |
|
||||
| --- | --- | --- |
|
||||
| `save_system` / `save_user` | Saving (`analyze_for_save`) | Inferred `suggested_scope`, `categories`, `importance`, and `extracted_metadata` before storage and embedding. |
|
||||
| `query_system` / `query_user` | Recall query analysis (`analyze_query`) | `keywords`, `suggested_scopes`, `complexity`, `recall_queries`, and `time_filter`, which steer vector search and how deep recall goes. |
|
||||
| `extract_memories_system` / `extract_memories_user` | `extract_memories_from_content` / `Memory.extract_memories` | How raw text is split into discrete memory strings (persistence is still via `remember()`). |
|
||||
| `consolidation_system` / `consolidation_user` | When new content is similar to existing records (`analyze_for_consolidation`) | Whether to keep, update, or delete existing rows and whether to insert the new content as its own memory. |
|
||||
|
||||
### Placeholders
|
||||
|
||||
**System** strings are sent as-is. **User** strings are filled with Python’s `str.format`. Custom user templates must include the same placeholder names as the defaults or formatting will raise.
|
||||
|
||||
| User field | Required placeholders |
|
||||
| --- | --- |
|
||||
| `save_user` | `{content}`, `{existing_scopes}`, `{existing_categories}` |
|
||||
| `query_user` | `{query}`, `{available_scopes}`, `{scope_desc}` |
|
||||
| `extract_memories_user` | `{content}` |
|
||||
| `consolidation_user` | `{new_content}`, `{records_summary}` |
|
||||
|
||||
## Hierarchical Scopes
|
||||
|
||||
|
||||
@@ -157,6 +157,43 @@ class ResearchFlow(Flow):
|
||||
|
||||
Flow에서의 메모리에 대한 자세한 내용은 [Flows 문서](/concepts/flows)를 참조하세요.
|
||||
|
||||
## 메모리 프롬프트 사용자 지정 (`MemoryPromptConfig`)
|
||||
|
||||
메모리 분석 단계마다 사용되는 LLM 지시문을 덮어쓸 수 있습니다(플래닝 프롬프트를 조정하는 것과 같은 개념). `Memory`의 `memory_prompt`에 `MemoryPromptConfig`를 넘깁니다. 필요한 필드만 설정하면 되고, 나머지 단계는 라이브러리 번들 기본값(`translations/en.json`의 `memory` 키; 필드 이름이 해당 JSON 키와 일치)을 그대로 씁니다.
|
||||
|
||||
```python
|
||||
from crewai import Memory, MemoryPromptConfig
|
||||
|
||||
memory = Memory(
|
||||
llm="gpt-4o-mini",
|
||||
memory_prompt=MemoryPromptConfig(
|
||||
save_system="...", # 선택
|
||||
query_user="...", # 선택
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
`crewai.memory.analyze`의 헬퍼(예: `extract_memories_from_content`)를 직접 호출할 때도 `memory_prompt`를 넘길 수 있습니다.
|
||||
|
||||
### 프롬프트 쌍별 역할
|
||||
|
||||
| 필드 | 실행 시점 | 영향 |
|
||||
| --- | --- | --- |
|
||||
| `save_system` / `save_user` | 저장 시 (`analyze_for_save`) | 저장·임베딩 전에 추론되는 `suggested_scope`, `categories`, `importance`, `extracted_metadata`. |
|
||||
| `query_system` / `query_user` | 리콜 시 쿼리 분석 (`analyze_query`) | `keywords`, `suggested_scopes`, `complexity`, `recall_queries`, `time_filter` — 벡터 검색과 리콜 탐색 깊이에 영향. |
|
||||
| `extract_memories_system` / `extract_memories_user` | `extract_memories_from_content` / `Memory.extract_memories` | 긴 텍스트를 개별 메모리 문자열로 나누는 방식(저장은 여전히 `remember()`). |
|
||||
| `consolidation_system` / `consolidation_user` | 신규 콘텐츠가 기존 레코드와 유사할 때 (`analyze_for_consolidation`) | 기존 행 유지·갱신·삭제 및 신규 콘텐츠를 별도 메모리로 넣을지 여부. |
|
||||
|
||||
### 플레이스홀더
|
||||
|
||||
**system** 문자열은 그대로 전송됩니다. **user** 문자열은 Python `str.format`으로 채워집니다. 사용자 정의 user 템플릿에는 기본값과 동일한 플레이스홀더 이름이 포함되어야 하며, 그렇지 않으면 포맷 단계에서 오류가 납니다.
|
||||
|
||||
| User 필드 | 필수 플레이스홀더 |
|
||||
| --- | --- |
|
||||
| `save_user` | `{content}`, `{existing_scopes}`, `{existing_categories}` |
|
||||
| `query_user` | `{query}`, `{available_scopes}`, `{scope_desc}` |
|
||||
| `extract_memories_user` | `{content}` |
|
||||
| `consolidation_user` | `{new_content}`, `{records_summary}` |
|
||||
|
||||
## 계층적 범위(Scopes)
|
||||
|
||||
|
||||
@@ -157,6 +157,43 @@ class ResearchFlow(Flow):
|
||||
|
||||
Veja a [documentação de Flows](/concepts/flows) para mais informações sobre memória em Flows.
|
||||
|
||||
## Personalizando prompts de memória (`MemoryPromptConfig`)
|
||||
|
||||
Substitua as instruções do LLM usadas em cada etapa de análise de memória (mesma ideia que ajustar prompts de planejamento). Passe um `MemoryPromptConfig` como `memory_prompt` em `Memory`. Defina apenas os campos necessários; nas demais etapas permanecem os padrões embutidos do `translations/en.json` da biblioteca, na chave `memory` (os nomes dos campos correspondem às chaves JSON).
|
||||
|
||||
```python
|
||||
from crewai import Memory, MemoryPromptConfig
|
||||
|
||||
memory = Memory(
|
||||
llm="gpt-4o-mini",
|
||||
memory_prompt=MemoryPromptConfig(
|
||||
save_system="...", # opcional
|
||||
query_user="...", # opcional
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
Você também pode passar `memory_prompt` para funções auxiliares em `crewai.memory.analyze` (por exemplo `extract_memories_from_content`) quando chamá-las diretamente.
|
||||
|
||||
### O que cada par de prompts afeta
|
||||
|
||||
| Campos | Quando roda | O que influencia |
|
||||
| --- | --- | --- |
|
||||
| `save_system` / `save_user` | Ao salvar (`analyze_for_save`) | `suggested_scope`, `categories`, `importance` e `extracted_metadata` inferidos antes do armazenamento e do embedding. |
|
||||
| `query_system` / `query_user` | Análise da consulta no recall (`analyze_query`) | `keywords`, `suggested_scopes`, `complexity`, `recall_queries` e `time_filter`, que orientam a busca vetorial e a profundidade do recall. |
|
||||
| `extract_memories_system` / `extract_memories_user` | `extract_memories_from_content` / `Memory.extract_memories` | Como o texto bruto é dividido em memórias atômicas (a persistência continua sendo via `remember()`). |
|
||||
| `consolidation_system` / `consolidation_user` | Quando o novo conteúdo é semelhante a registros existentes (`analyze_for_consolidation`) | Manter, atualizar ou excluir linhas existentes e se o novo conteúdo entra como memória própria. |
|
||||
|
||||
### Placeholders
|
||||
|
||||
Strings de **system** são enviadas como estão. Strings de **user** são preenchidas com `str.format` do Python. Templates de user personalizados devem incluir os mesmos nomes de placeholder dos padrões; caso contrário, a formatação falha.
|
||||
|
||||
| Campo user | Placeholders obrigatórios |
|
||||
| --- | --- |
|
||||
| `save_user` | `{content}`, `{existing_scopes}`, `{existing_categories}` |
|
||||
| `query_user` | `{query}`, `{available_scopes}`, `{scope_desc}` |
|
||||
| `extract_memories_user` | `{content}` |
|
||||
| `consolidation_user` | `{new_content}`, `{records_summary}` |
|
||||
|
||||
## Escopos Hierárquicos
|
||||
|
||||
|
||||
Reference in New Issue
Block a user