mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-09-22 10:56:50 +00:00
feat(experimental): add /btw commands to steer conversational flows
Opt-in add-on that intercepts /btw lines before handle_turn so users can inject steering notes or force a route without recording a user turn. Co-authored-by: Lorenze Jay <lorenzejay@users.noreply.github.com>
This commit is contained in:
@@ -612,6 +612,44 @@ from crewai.flow import (
|
||||
)
|
||||
```
|
||||
|
||||
## تجريبي: أوامر `/btw`
|
||||
|
||||
<Warning>
|
||||
`/btw` إضافة تجريبية. تتجاهل التدفقات المحادثية أسطر الأوامر حتى تفعّلها صراحة، وقد يتغيّر الـ API.
|
||||
</Warning>
|
||||
|
||||
يعامل كل `handle_turn()` سطر المستخدم كتشغيل جديد للرسم. `/btw` قناة جانبية تتيح لك إدخال ملاحظة توجيه — أو فرض مسار — **دون** إلحاق رسالة مستخدم أو تشغيل الرسم.
|
||||
|
||||
```python
|
||||
from crewai.experimental.conversation_commands import btw_commands
|
||||
from crewai.flow import ConversationConfig, ConversationState, Flow, listen
|
||||
|
||||
|
||||
@btw_commands
|
||||
@ConversationConfig()
|
||||
class SupportFlow(Flow[ConversationState]):
|
||||
@listen("RESEARCH")
|
||||
def handle_research(self) -> str:
|
||||
"""Fresh web research."""
|
||||
reply = "I would research that."
|
||||
self.append_assistant_message(reply)
|
||||
return reply
|
||||
```
|
||||
|
||||
| السطر | الأثر |
|
||||
|------|--------|
|
||||
| `/btw keep answers under 20 words` | يحفظ ملاحظة توجيه. لا تُسجَّل جولة مستخدم. تظهر الملاحظة لاحقاً في مطالبات `converse` والموجّه. |
|
||||
| `/btw route RESEARCH` | يفرض المسار على **الجولة التالية** ثم يعود للتوجيه العادي. |
|
||||
| `/btw stay RESEARCH` أو `/btw route RESEARCH persist` | يواصل فرض ذلك المسار حتى `/btw clear`. |
|
||||
| `/btw clear` | يحذف الملاحظات والمسارات المفروضة. |
|
||||
| `/btw` أو `/btw show` | يعرض التوجيه الحالي. |
|
||||
| `/help` | يسرد الأوامر. |
|
||||
| `What's the weather /btw keep it to one sentence` | يطبّق الأمر ثم يشغّل النص المتبقي كجولة مستخدم. |
|
||||
|
||||
لتدفق أنشأته مسبقاً (بما في ذلك `Flow.from_declaration(...)`)، استدعِ `enable_btw_commands(flow)` بدل المزيّن.
|
||||
|
||||
أسطر `/btw` المستقلة تعيد إقراراً ولا تستدعي `kickoff()`. ولأن `chat()` وواجهة CLI TUI تغلفان `handle_turn()`، تلتقطان الإضافة تلقائياً بعد تثبيتها. التدفقات بدون الإضافة ما زالت تعامل `/btw …` كرسالة مستخدم عادية.
|
||||
|
||||
## مراجع
|
||||
|
||||
- [إتقان إدارة حالة Flow](/ar/guides/flows/mastering-flow-state)
|
||||
|
||||
@@ -613,6 +613,44 @@ from crewai.flow import (
|
||||
)
|
||||
```
|
||||
|
||||
## Experimental: `/btw` commands
|
||||
|
||||
<Warning>
|
||||
`/btw` is an experimental add-on. Conversational flows ignore slash lines until you opt in, and the API may change.
|
||||
</Warning>
|
||||
|
||||
Each `handle_turn()` treats the user line as a new graph run. `/btw` is a side-channel so you can interject a steering note — or force a route — **without** appending a user message or running the graph.
|
||||
|
||||
```python
|
||||
from crewai.experimental.conversation_commands import btw_commands
|
||||
from crewai.flow import ConversationConfig, ConversationState, Flow, listen
|
||||
|
||||
|
||||
@btw_commands
|
||||
@ConversationConfig()
|
||||
class SupportFlow(Flow[ConversationState]):
|
||||
@listen("RESEARCH")
|
||||
def handle_research(self) -> str:
|
||||
"""Fresh web research."""
|
||||
reply = "I would research that."
|
||||
self.append_assistant_message(reply)
|
||||
return reply
|
||||
```
|
||||
|
||||
| Line | Effect |
|
||||
|------|--------|
|
||||
| `/btw keep answers under 20 words` | Persist a steering note. No user turn is recorded. Later `converse` and router prompts include the note. |
|
||||
| `/btw route RESEARCH` | Force the **next** turn onto that route, then resume normal routing. |
|
||||
| `/btw stay RESEARCH` or `/btw route RESEARCH persist` | Keep forcing that route until `/btw clear`. |
|
||||
| `/btw clear` | Drop notes and forced routes. |
|
||||
| `/btw` or `/btw show` | Print the current steering. |
|
||||
| `/help` | List commands. |
|
||||
| `What's the weather /btw keep it to one sentence` | Apply the command, then run the leftover text as the user turn. |
|
||||
|
||||
For a flow you already constructed (including `Flow.from_declaration(...)`), call `enable_btw_commands(flow)` instead of the decorator.
|
||||
|
||||
Standalone `/btw` lines return an acknowledgement and do not call `kickoff()`. Because `chat()` and the CLI TUI wrap `handle_turn()`, they pick the add-on up automatically once it is installed. Flows without the add-on still treat `/btw …` as a normal user message.
|
||||
|
||||
## See also
|
||||
|
||||
- [Mastering Flow State Management](/en/guides/flows/mastering-flow-state) — persistence, Pydantic state, `@persist`
|
||||
|
||||
@@ -608,6 +608,44 @@ from crewai.flow import (
|
||||
)
|
||||
```
|
||||
|
||||
## 실험적: `/btw` 명령
|
||||
|
||||
<Warning>
|
||||
`/btw`는 실험적 애드온입니다. 대화형 Flow는 명시적으로 켜기 전까지 슬래시 줄을 무시하며, API는 바뀔 수 있습니다.
|
||||
</Warning>
|
||||
|
||||
각 `handle_turn()`은 사용자 줄을 새로운 그래프 실행으로 취급합니다. `/btw`는 사이드 채널이므로 사용자 메시지를 추가하거나 그래프를 실행하지 **않고** 스티어링 노트(또는 강제 라우트)를 끼워 넣을 수 있습니다.
|
||||
|
||||
```python
|
||||
from crewai.experimental.conversation_commands import btw_commands
|
||||
from crewai.flow import ConversationConfig, ConversationState, Flow, listen
|
||||
|
||||
|
||||
@btw_commands
|
||||
@ConversationConfig()
|
||||
class SupportFlow(Flow[ConversationState]):
|
||||
@listen("RESEARCH")
|
||||
def handle_research(self) -> str:
|
||||
"""Fresh web research."""
|
||||
reply = "I would research that."
|
||||
self.append_assistant_message(reply)
|
||||
return reply
|
||||
```
|
||||
|
||||
| 줄 | 효과 |
|
||||
|------|--------|
|
||||
| `/btw keep answers under 20 words` | 스티어링 노트를 유지합니다. 사용자 턴은 기록되지 않습니다. 이후 `converse`와 라우터 프롬프트에 노트가 포함됩니다. |
|
||||
| `/btw route RESEARCH` | **다음** 턴만 해당 라우트로 강제하고 이후에는 일반 라우팅으로 돌아갑니다. |
|
||||
| `/btw stay RESEARCH` 또는 `/btw route RESEARCH persist` | `/btw clear` 전까지 그 라우트를 계속 강제합니다. |
|
||||
| `/btw clear` | 노트와 강제 라우트를 제거합니다. |
|
||||
| `/btw` 또는 `/btw show` | 현재 스티어링을 보여 줍니다. |
|
||||
| `/help` | 명령 목록을 출력합니다. |
|
||||
| `What's the weather /btw keep it to one sentence` | 명령을 적용한 뒤 남은 텍스트를 사용자 턴으로 실행합니다. |
|
||||
|
||||
이미 만든 Flow( `Flow.from_declaration(...)` 포함)에는 데코레이터 대신 `enable_btw_commands(flow)`를 호출하세요.
|
||||
|
||||
단독 `/btw` 줄은 확인 메시지를 반환하며 `kickoff()`를 호출하지 않습니다. `chat()`과 CLI TUI는 `handle_turn()`을 감싸므로, 애드온이 설치된 뒤에는 자동으로 동작합니다. 애드온이 없는 Flow는 `/btw …`를 일반 사용자 메시지로 취급합니다.
|
||||
|
||||
## 참고
|
||||
|
||||
- [Flow 상태 관리 마스터하기](/ko/guides/flows/mastering-flow-state)
|
||||
|
||||
@@ -613,6 +613,44 @@ from crewai.flow import (
|
||||
)
|
||||
```
|
||||
|
||||
## Experimental: comandos `/btw`
|
||||
|
||||
<Warning>
|
||||
`/btw` é um extra experimental. Flows conversacionais ignoram linhas com barra até você ativar o extra, e a API pode mudar.
|
||||
</Warning>
|
||||
|
||||
Cada `handle_turn()` trata a linha do usuário como uma nova execução do grafo. `/btw` é um canal lateral para intercalar uma nota de direção — ou forçar uma rota — **sem** anexar uma mensagem de usuário nem rodar o grafo.
|
||||
|
||||
```python
|
||||
from crewai.experimental.conversation_commands import btw_commands
|
||||
from crewai.flow import ConversationConfig, ConversationState, Flow, listen
|
||||
|
||||
|
||||
@btw_commands
|
||||
@ConversationConfig()
|
||||
class SupportFlow(Flow[ConversationState]):
|
||||
@listen("RESEARCH")
|
||||
def handle_research(self) -> str:
|
||||
"""Fresh web research."""
|
||||
reply = "I would research that."
|
||||
self.append_assistant_message(reply)
|
||||
return reply
|
||||
```
|
||||
|
||||
| Linha | Efeito |
|
||||
|------|--------|
|
||||
| `/btw keep answers under 20 words` | Persiste uma nota de direção. Nenhum turno de usuário é gravado. As notas entram depois nos prompts de `converse` e do router. |
|
||||
| `/btw route RESEARCH` | Força o **próximo** turno para essa rota e depois volta ao roteamento normal. |
|
||||
| `/btw stay RESEARCH` ou `/btw route RESEARCH persist` | Continua forçando essa rota até `/btw clear`. |
|
||||
| `/btw clear` | Remove notas e rotas forçadas. |
|
||||
| `/btw` ou `/btw show` | Mostra a direção atual. |
|
||||
| `/help` | Lista os comandos. |
|
||||
| `What's the weather /btw keep it to one sentence` | Aplica o comando e executa o texto restante como turno do usuário. |
|
||||
|
||||
Para um flow já construído (incluindo `Flow.from_declaration(...)`), chame `enable_btw_commands(flow)` em vez do decorator.
|
||||
|
||||
Linhas `/btw` isoladas devolvem um acknowledgement e não chamam `kickoff()`. Como `chat()` e o TUI da CLI encapsulam `handle_turn()`, o extra passa a valer automaticamente depois de instalado. Flows sem o extra ainda tratam `/btw …` como mensagem normal de usuário.
|
||||
|
||||
## Veja também
|
||||
|
||||
- [Dominando o Gerenciamento de Estado em Flows](/pt-BR/guides/flows/mastering-flow-state) — persistência, estado Pydantic, `@persist`
|
||||
|
||||
Reference in New Issue
Block a user