mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-08-30 09:48:00 +00:00
docs: rewrite FileWriterTool page in plain reference style
Align the docs with the sandbox, overwrite, encoding, and base_dir behavior in the implementation. Drop marketing copy and the conclusion. Co-authored-by: Rip&Tear <theCyberTech@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: كتابة الملفات
|
||||
description: أداة `FileWriterTool` مصممة لكتابة المحتوى في الملفات.
|
||||
description: تكتب محتوى نصيًا إلى ملف.
|
||||
icon: file-pen
|
||||
mode: "wide"
|
||||
---
|
||||
@@ -9,27 +9,25 @@ mode: "wide"
|
||||
|
||||
## الوصف
|
||||
|
||||
أداة `FileWriterTool` هي مكوّن من حزمة crewai_tools، مصممة لتبسيط عملية كتابة المحتوى في الملفات مع توافق عبر المنصات (Windows و Linux و macOS). تكون مفيدة بشكل خاص في سيناريوهات مثل توليد التقارير وحفظ السجلات وإنشاء ملفات التكوين والمزيد. تتعامل هذه الأداة مع اختلافات المسارات عبر أنظمة التشغيل، وتدعم ترميز UTF-8، وتنشئ المجلدات تلقائياً إذا لم تكن موجودة، مما يسهل تنظيم المخرجات بشكل موثوق عبر المنصات المختلفة.
|
||||
تكتب `FileWriterTool` محتوى نصيًا إلى ملف. تُنشأ المجلدات المفقودة تلقائيًا.
|
||||
ترميز النص الافتراضي هو UTF-8.
|
||||
|
||||
تقتصر عمليات الكتابة على مجلد sandbox. بشكل افتراضي يكون هذا المجلد هو مجلد
|
||||
العمل الحالي. مرّر `base_dir` لتغييره.
|
||||
|
||||
## التثبيت
|
||||
|
||||
قم بتثبيت حزمة crewai_tools لاستخدام `FileWriterTool` في مشاريعك:
|
||||
|
||||
```shell
|
||||
pip install 'crewai[tools]'
|
||||
```
|
||||
|
||||
## مثال
|
||||
|
||||
للبدء مع `FileWriterTool`:
|
||||
|
||||
```python Code
|
||||
from crewai_tools import FileWriterTool
|
||||
|
||||
# Initialize the tool
|
||||
file_writer_tool = FileWriterTool()
|
||||
|
||||
# Write content to a file in a specified directory
|
||||
result = file_writer_tool.run(
|
||||
filename='example.txt',
|
||||
content='This is a test content.',
|
||||
@@ -40,12 +38,46 @@ print(result)
|
||||
|
||||
## المعاملات
|
||||
|
||||
- `filename`: اسم الملف الذي تريد إنشاءه أو الكتابة فوقه.
|
||||
- `content`: المحتوى المراد كتابته في الملف.
|
||||
- `directory` (اختياري): مسار المجلد حيث سيتم إنشاء الملف. الافتراضي هو المجلد الحالي (`.`). إذا لم يكن المجلد موجوداً، سيتم إنشاؤه.
|
||||
يوفّرها الوكيل في وقت التشغيل:
|
||||
|
||||
## الخلاصة
|
||||
- `filename`: اسم الملف المراد كتابته، نسبةً إلى `directory`. يمكن أن يتضمن
|
||||
مجلدات فرعية. تُنشأ تلك المجلدات الفرعية إذا لم تكن موجودة.
|
||||
- `content`: المحتوى النصي المراد كتابته.
|
||||
- `directory` (اختياري): المجلد الذي تتم الكتابة إليه. يُحل المسار النسبي
|
||||
داخل المجلد المسموح للأداة (`base_dir` عند تعيينه، وإلا مجلد العمل الحالي)
|
||||
ويُعيَّن افتراضيًا إلى جذر ذلك المجلد (`./`). يُنشأ إذا لم يكن موجودًا.
|
||||
- `overwrite` (اختياري): ما إذا كان يجب استبدال ملف موجود. يقبل قيمة منطقية
|
||||
أو السلاسل `y`/`yes`/`t`/`true`/`on`/`1` و
|
||||
`n`/`no`/`f`/`false`/`off`/`0`. الافتراضي هو `false`. عندما يكون `false`
|
||||
والملف موجودًا مسبقًا، تُرجع الأداة خطأً ولا تعدّل الملف.
|
||||
|
||||
من خلال دمج `FileWriterTool` في أطقمك، يمكن للوكلاء كتابة المحتوى في الملفات بشكل موثوق عبر أنظمة التشغيل المختلفة. هذه الأداة ضرورية للمهام التي تتطلب حفظ بيانات المخرجات وإنشاء أنظمة ملفات منظمة والتعامل مع عمليات الملفات عبر المنصات. يُوصى بها بشكل خاص لمستخدمي Windows الذين قد يواجهون مشكلات في كتابة الملفات مع عمليات ملفات Python القياسية.
|
||||
تُعيَّن هذه عند إنشاء الأداة:
|
||||
|
||||
من خلال الالتزام بإرشادات الإعداد والاستخدام المقدمة، فإن دمج هذه الأداة في المشاريع أمر مباشر ويضمن سلوكاً متسقاً لكتابة الملفات عبر جميع المنصات.
|
||||
- `base_dir` (اختياري): المجلد الذي يجب أن تبقى عمليات الكتابة داخله.
|
||||
الافتراضي هو مجلد العمل الحالي. يُحل المسار النسبي عند إنشاء الأداة، لذا
|
||||
لا ينقل تغيير لاحق لمجلد العمل حدود الـ sandbox.
|
||||
- `encoding` (اختياري): ترميز النص المستخدم لكتابة الملف. الافتراضي هو
|
||||
`utf-8`.
|
||||
|
||||
## المسارات المسموح بها
|
||||
|
||||
عادةً ما يختار نموذج لغوي قيم `directory` و`filename` في وقت التشغيل. ترفض
|
||||
الأداة المسارات التي تخرج من الـ sandbox:
|
||||
|
||||
- يجب أن يكون `directory` المحلول داخل `base_dir` (مجلد العمل الحالي
|
||||
افتراضيًا).
|
||||
- يجب أن يكون مسار الملف المحلول داخل ذلك `directory`.
|
||||
- تُحل مقاطع `..` والمسارات المطلقة والروابط الرمزية قبل كلا الفحصين.
|
||||
|
||||
للسماح بالكتابة تحت شجرة مختلفة، عيّن `base_dir`:
|
||||
|
||||
```python Code
|
||||
file_writer_tool = FileWriterTool(base_dir='/var/output')
|
||||
```
|
||||
|
||||
<Note>
|
||||
سابقًا، كان بإمكان `directory` المطلق الكتابة في أي مكان يملك فيه العملية
|
||||
صلاحية. إذا اعتمدت على ذلك، عيّن `base_dir` إلى الشجرة التي تريد السماح بها.
|
||||
تعيين `CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true` يعيد السلوك القديم، لكنه يعطّل
|
||||
فحوصات المسار وURL على مستوى العملية لكل أدوات crewai-tools. فضّل `base_dir`.
|
||||
</Note>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: File Write
|
||||
description: The `FileWriterTool` is designed to write content to files.
|
||||
description: Writes text content to a file.
|
||||
icon: file-pen
|
||||
mode: "wide"
|
||||
---
|
||||
@@ -9,29 +9,25 @@ mode: "wide"
|
||||
|
||||
## Description
|
||||
|
||||
The `FileWriterTool` is a component of the crewai_tools package, designed to simplify the process of writing content to files with cross-platform compatibility (Windows, Linux, macOS).
|
||||
It is particularly useful in scenarios such as generating reports, saving logs, creating configuration files, and more.
|
||||
This tool handles path differences across operating systems, writes UTF-8 by default rather than the platform's locale encoding, and automatically creates directories if they don't exist, making it easier to organize your output reliably across different platforms.
|
||||
`FileWriterTool` writes text content to a file. Missing directories are created
|
||||
automatically. The default text encoding is UTF-8.
|
||||
|
||||
Writes are confined to a sandbox directory. By default that directory is the
|
||||
current working directory. Pass `base_dir` to change it.
|
||||
|
||||
## Installation
|
||||
|
||||
Install the crewai_tools package to use the `FileWriterTool` in your projects:
|
||||
|
||||
```shell
|
||||
pip install 'crewai[tools]'
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
To get started with the `FileWriterTool`:
|
||||
|
||||
```python Code
|
||||
from crewai_tools import FileWriterTool
|
||||
|
||||
# Initialize the tool
|
||||
file_writer_tool = FileWriterTool()
|
||||
|
||||
# Write content to a file in a specified directory
|
||||
result = file_writer_tool.run(
|
||||
filename='example.txt',
|
||||
content='This is a test content.',
|
||||
@@ -44,38 +40,47 @@ print(result)
|
||||
|
||||
The agent supplies these at runtime:
|
||||
|
||||
- `filename`: The name of the file to write, relative to `directory`. May include subdirectories, which are created if they don't exist.
|
||||
- `content`: The text content to write into the file.
|
||||
- `directory` (optional): The path to the directory where the file will be created. A relative path resolves inside the tool's allowed directory — `base_dir` when set, the current working directory otherwise — and defaults to its root. If the directory does not exist, it will be created.
|
||||
- `overwrite` (optional): Whether to replace the file when it already exists. Accepts `true`/`false` (also `yes`/`no`, `on`/`off`, `1`/`0`). Defaults to `false`, which reports an error instead of replacing existing content.
|
||||
- `filename`: Name of the file to write, relative to `directory`. May include
|
||||
subdirectories. Those subdirectories are created if they do not exist.
|
||||
- `content`: Text content to write.
|
||||
- `directory` (optional): Directory to write into. A relative path resolves
|
||||
inside the tool's allowed directory (`base_dir` when set, otherwise the
|
||||
current working directory) and defaults to that directory's root (`./`).
|
||||
Created if it does not exist.
|
||||
- `overwrite` (optional): Whether to replace an existing file. Accepts a
|
||||
boolean or the strings `y`/`yes`/`t`/`true`/`on`/`1` and
|
||||
`n`/`no`/`f`/`false`/`off`/`0`. Defaults to `false`. When `false` and the
|
||||
file already exists, the tool returns an error and does not modify the file.
|
||||
|
||||
You set these when constructing the tool:
|
||||
|
||||
- `base_dir` (optional): The directory that writes must stay inside. Defaults to the current working directory.
|
||||
- `encoding` (optional): Text encoding used to write the file. Defaults to `utf-8`.
|
||||
- `base_dir` (optional): Directory that writes must stay inside. Defaults to
|
||||
the current working directory. A relative path is resolved when the tool is
|
||||
constructed, so a later change of working directory does not move the
|
||||
sandbox.
|
||||
- `encoding` (optional): Text encoding used to write the file. Defaults to
|
||||
`utf-8`.
|
||||
|
||||
## Allowed paths
|
||||
|
||||
Because both the directory and the filename are usually chosen by an LLM at runtime, writes are confined to a sandbox:
|
||||
Runtime `directory` and `filename` values are usually chosen by an LLM. The
|
||||
tool rejects paths that escape the sandbox:
|
||||
|
||||
- The resolved `directory` must be inside `base_dir`, which defaults to the current working directory.
|
||||
- The resolved file must then be inside that `directory`. `..` segments, absolute paths, and symlinks are resolved before both checks, so they cannot be used to escape.
|
||||
- The resolved `directory` must be inside `base_dir` (the current working
|
||||
directory by default).
|
||||
- The resolved file path must be inside that `directory`.
|
||||
- `..` segments, absolute paths, and symlinks are resolved before both checks.
|
||||
|
||||
To let an agent write outside the working directory, point `base_dir` at the target tree:
|
||||
To allow writes under a different tree, set `base_dir`:
|
||||
|
||||
```python Code
|
||||
# The agent may write anywhere under /var/output, and nowhere outside it
|
||||
file_writer_tool = FileWriterTool(base_dir='/var/output')
|
||||
```
|
||||
|
||||
<Note>
|
||||
Previously an absolute `directory` could write anywhere the process had permission to. If you relied on that, set `base_dir` to the tree you want to allow. Setting `CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true` restores the old behavior, but it applies process-wide to every crewai-tools tool, including the SSRF protections on URL-fetching tools, so prefer `base_dir`.
|
||||
Previously, an absolute `directory` could write anywhere the process had
|
||||
permission. If you relied on that, set `base_dir` to the tree you want to
|
||||
allow. Setting `CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true` restores the old
|
||||
behavior, but it disables path and URL checks process-wide for every
|
||||
crewai-tools tool. Prefer `base_dir`.
|
||||
</Note>
|
||||
|
||||
## Conclusion
|
||||
|
||||
By integrating the `FileWriterTool` into your crews, the agents can reliably write content to files across different operating systems.
|
||||
This tool is essential for tasks that require saving output data, creating structured file systems, and handling cross-platform file operations.
|
||||
It's particularly recommended for Windows users who may encounter file writing issues with standard Python file operations.
|
||||
|
||||
By adhering to the setup and usage guidelines provided, incorporating this tool into projects is straightforward and ensures consistent file writing behavior across all platforms.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 파일 쓰기
|
||||
description: FileWriterTool은 파일에 내용을 쓰도록 설계되었습니다.
|
||||
description: 텍스트 내용을 파일에 씁니다.
|
||||
icon: file-pen
|
||||
mode: "wide"
|
||||
---
|
||||
@@ -9,29 +9,25 @@ mode: "wide"
|
||||
|
||||
## 설명
|
||||
|
||||
`FileWriterTool`은 crewai_tools 패키지의 구성 요소로, 다양한 운영 체제(Windows, Linux, macOS)에서 파일에 내용을 작성하는 과정을 간소화하도록 설계되었습니다.
|
||||
이 도구는 보고서 생성, 로그 저장, 설정 파일 작성 등과 같은 시나리오에서 특히 유용합니다.
|
||||
운영 체제마다 다른 경로 처리를 지원하며, UTF-8 인코딩을 지원하고, 디렉토리가 존재하지 않으면 자동으로 생성하여, 다양한 플랫폼에서 출력 결과를 안정적으로 정리할 수 있도록 도와줍니다.
|
||||
`FileWriterTool`은 텍스트 내용을 파일에 씁니다. 없는 디렉터리는 자동으로
|
||||
만들어집니다. 기본 텍스트 인코딩은 UTF-8입니다.
|
||||
|
||||
쓰기는 샌드박스 디렉터리로 제한됩니다. 기본적으로 이 디렉터리는 현재 작업
|
||||
디렉터리입니다. 변경하려면 `base_dir`을 전달하세요.
|
||||
|
||||
## 설치
|
||||
|
||||
프로젝트에서 `FileWriterTool`을 사용하려면 crewai_tools 패키지를 설치하세요:
|
||||
|
||||
```shell
|
||||
pip install 'crewai[tools]'
|
||||
```
|
||||
|
||||
## 예시
|
||||
|
||||
`FileWriterTool`을(를) 시작하려면:
|
||||
|
||||
```python Code
|
||||
from crewai_tools import FileWriterTool
|
||||
|
||||
# Initialize the tool
|
||||
file_writer_tool = FileWriterTool()
|
||||
|
||||
# Write content to a file in a specified directory
|
||||
result = file_writer_tool.run(
|
||||
filename='example.txt',
|
||||
content='This is a test content.',
|
||||
@@ -42,14 +38,49 @@ print(result)
|
||||
|
||||
## 인자
|
||||
|
||||
- `filename`: 생성하거나 덮어쓸 파일의 이름입니다.
|
||||
- `content`: 파일에 쓸 내용입니다.
|
||||
- `directory` (선택 사항): 파일이 생성될 디렉터리의 경로입니다. 기본값은 현재 디렉터리(`.`)입니다. 디렉터리가 존재하지 않으면 생성됩니다.
|
||||
에이전트가 런타임에 제공하는 값:
|
||||
|
||||
## 결론
|
||||
- `filename`: `directory`를 기준으로 쓸 파일 이름입니다. 하위 디렉터리를
|
||||
포함할 수 있으며, 없는 하위 디렉터리는 생성됩니다.
|
||||
- `content`: 쓸 텍스트 내용입니다.
|
||||
- `directory` (선택 사항): 파일을 쓸 디렉터리입니다. 상대 경로는 도구의
|
||||
허용 디렉터리(`base_dir`이 설정된 경우 그 값, 그렇지 않으면 현재 작업
|
||||
디렉터리) 안에서 해석되며, 기본값은 해당 디렉터리의 루트(`./`)입니다.
|
||||
없으면 생성됩니다.
|
||||
- `overwrite` (선택 사항): 기존 파일을 덮어쓸지 여부입니다. 불리언 또는
|
||||
문자열 `y`/`yes`/`t`/`true`/`on`/`1` 및
|
||||
`n`/`no`/`f`/`false`/`off`/`0`을 받습니다. 기본값은 `false`입니다.
|
||||
`false`이고 파일이 이미 있으면 도구는 오류를 반환하고 파일을 수정하지
|
||||
않습니다.
|
||||
|
||||
`FileWriterTool`을 crew에 통합함으로써, 에이전트는 다양한 운영 체제에서 파일에 내용을 안정적으로 쓸 수 있습니다.
|
||||
이 도구는 출력 데이터를 저장하거나, 구조화된 파일 시스템을 생성하거나, 크로스 플랫폼 파일 작업을 처리해야 하는 작업에 필수적입니다.
|
||||
특히 표준 Python 파일 작업에서 파일 쓰기 이슈가 발생할 수 있는 Windows 사용자에게 권장됩니다.
|
||||
도구를 생성할 때 설정하는 값:
|
||||
|
||||
제공된 설정 및 사용 가이드라인을 준수하면, 이 도구를 프로젝트에 통합하는 과정이 간단하며 모든 플랫폼에서 일관된 파일 쓰기 동작을 보장합니다.
|
||||
- `base_dir` (선택 사항): 쓰기가 머물 수 있는 디렉터리입니다. 기본값은
|
||||
현재 작업 디렉터리입니다. 상대 경로는 도구가 생성될 때 해석되므로, 이후
|
||||
작업 디렉터리를 바꿔도 샌드박스는 이동하지 않습니다.
|
||||
- `encoding` (선택 사항): 파일을 쓸 때 사용하는 텍스트 인코딩입니다.
|
||||
기본값은 `utf-8`입니다.
|
||||
|
||||
## 허용 경로
|
||||
|
||||
런타임의 `directory`와 `filename` 값은 보통 LLM이 선택합니다. 도구는
|
||||
샌드박스를 벗어나는 경로를 거부합니다:
|
||||
|
||||
- 해석된 `directory`는 `base_dir`(기본값은 현재 작업 디렉터리) 안에 있어야
|
||||
합니다.
|
||||
- 해석된 파일 경로는 그 `directory` 안에 있어야 합니다.
|
||||
- 두 검사 전에 `..` 세그먼트, 절대 경로, 심볼릭 링크가 해석됩니다.
|
||||
|
||||
다른 트리 아래에 쓰기를 허용하려면 `base_dir`을 설정하세요:
|
||||
|
||||
```python Code
|
||||
file_writer_tool = FileWriterTool(base_dir='/var/output')
|
||||
```
|
||||
|
||||
<Note>
|
||||
이전에는 절대 `directory`가 프로세스 권한이 있는 임의의 위치에 쓸 수
|
||||
있었습니다. 그 동작에 의존했다면 허용할 트리로 `base_dir`을 설정하세요.
|
||||
`CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true`를 설정하면 이전 동작이 복원되지만,
|
||||
모든 crewai-tools 도구에 대해 프로세스 전역으로 경로 및 URL 검사가
|
||||
비활성화됩니다. `base_dir`을 선호하세요.
|
||||
</Note>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Escrita de Arquivo
|
||||
description: O `FileWriterTool` foi projetado para escrever conteúdo em arquivos.
|
||||
description: Escreve conteúdo de texto em um arquivo.
|
||||
icon: file-pen
|
||||
mode: "wide"
|
||||
---
|
||||
@@ -9,29 +9,25 @@ mode: "wide"
|
||||
|
||||
## Descrição
|
||||
|
||||
O `FileWriterTool` é um componente do pacote crewai_tools, projetado para simplificar o processo de escrita de conteúdo em arquivos com compatibilidade multiplataforma (Windows, Linux, macOS).
|
||||
É particularmente útil em cenários como geração de relatórios, salvamento de logs, criação de arquivos de configuração e mais.
|
||||
Essa ferramenta lida com diferenças de caminhos entre sistemas operacionais, suporta codificação UTF-8 e cria diretórios automaticamente caso eles não existam, facilitando a organização da sua saída de forma confiável em diferentes plataformas.
|
||||
O `FileWriterTool` escreve conteúdo de texto em um arquivo. Diretórios
|
||||
ausentes são criados automaticamente. A codificação de texto padrão é UTF-8.
|
||||
|
||||
As escritas ficam confinadas a um diretório sandbox. Por padrão, esse
|
||||
diretório é o diretório de trabalho atual. Passe `base_dir` para alterá-lo.
|
||||
|
||||
## Instalação
|
||||
|
||||
Instale o pacote crewai_tools para utilizar o `FileWriterTool` em seus projetos:
|
||||
|
||||
```shell
|
||||
pip install 'crewai[tools]'
|
||||
```
|
||||
|
||||
## Exemplo
|
||||
|
||||
Para começar a usar o `FileWriterTool`:
|
||||
|
||||
```python Code
|
||||
from crewai_tools import FileWriterTool
|
||||
|
||||
# Inicialize a ferramenta
|
||||
file_writer_tool = FileWriterTool()
|
||||
|
||||
# Escreva conteúdo em um arquivo em um diretório especificado
|
||||
result = file_writer_tool.run(
|
||||
filename='example.txt',
|
||||
content='This is a test content.',
|
||||
@@ -42,14 +38,50 @@ print(result)
|
||||
|
||||
## Argumentos
|
||||
|
||||
- `filename`: O nome do arquivo que você deseja criar ou sobrescrever.
|
||||
- `content`: O conteúdo a ser escrito no arquivo.
|
||||
- `directory` (opcional): O caminho para o diretório onde o arquivo será criado. Por padrão, utiliza o diretório atual (`.`). Se o diretório não existir, ele será criado.
|
||||
O agente fornece estes em tempo de execução:
|
||||
|
||||
## Conclusão
|
||||
- `filename`: Nome do arquivo a escrever, relativo a `directory`. Pode incluir
|
||||
subdiretórios. Esses subdiretórios são criados se não existirem.
|
||||
- `content`: Conteúdo de texto a escrever.
|
||||
- `directory` (opcional): Diretório no qual escrever. Um caminho relativo é
|
||||
resolvido dentro do diretório permitido da ferramenta (`base_dir` quando
|
||||
definido; caso contrário, o diretório de trabalho atual) e tem como padrão a
|
||||
raiz desse diretório (`./`). É criado se não existir.
|
||||
- `overwrite` (opcional): Se um arquivo existente deve ser substituído. Aceita
|
||||
um booleano ou as strings `y`/`yes`/`t`/`true`/`on`/`1` e
|
||||
`n`/`no`/`f`/`false`/`off`/`0`. O padrão é `false`. Quando é `false` e o
|
||||
arquivo já existe, a ferramenta retorna um erro e não modifica o arquivo.
|
||||
|
||||
Ao integrar o `FileWriterTool` aos seus crews, os agentes podem escrever conteúdo em arquivos de forma confiável em diferentes sistemas operacionais.
|
||||
Esta ferramenta é essencial para tarefas que exigem salvamento de dados de saída, criação de sistemas de arquivos estruturados e manipulação de operações de arquivos multiplataforma.
|
||||
É especialmente recomendada para usuários do Windows que possam enfrentar problemas ao escrever arquivos com as operações padrão do Python.
|
||||
Você define estes ao construir a ferramenta:
|
||||
|
||||
Seguindo as orientações de configuração e uso fornecidas, incorporar essa ferramenta em projetos é simples e garante um comportamento consistente de escrita de arquivos em todas as plataformas.
|
||||
- `base_dir` (opcional): Diretório dentro do qual as escritas devem
|
||||
permanecer. O padrão é o diretório de trabalho atual. Um caminho relativo é
|
||||
resolvido quando a ferramenta é construída, então uma mudança posterior do
|
||||
diretório de trabalho não move o sandbox.
|
||||
- `encoding` (opcional): Codificação de texto usada para escrever o arquivo.
|
||||
O padrão é `utf-8`.
|
||||
|
||||
## Caminhos permitidos
|
||||
|
||||
Os valores de `directory` e `filename` em tempo de execução costumam ser
|
||||
escolhidos por um LLM. A ferramenta rejeita caminhos que escapam do sandbox:
|
||||
|
||||
- O `directory` resolvido deve estar dentro de `base_dir` (o diretório de
|
||||
trabalho atual por padrão).
|
||||
- O caminho do arquivo resolvido deve estar dentro desse `directory`.
|
||||
- Segmentos `..`, caminhos absolutos e symlinks são resolvidos antes das duas
|
||||
verificações.
|
||||
|
||||
Para permitir escritas em outra árvore, defina `base_dir`:
|
||||
|
||||
```python Code
|
||||
file_writer_tool = FileWriterTool(base_dir='/var/output')
|
||||
```
|
||||
|
||||
<Note>
|
||||
Anteriormente, um `directory` absoluto podia escrever em qualquer lugar em que
|
||||
o processo tivesse permissão. Se você dependia disso, defina `base_dir` para a
|
||||
árvore que deseja permitir. Definir `CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true`
|
||||
restaura o comportamento antigo, mas desativa verificações de caminho e URL em
|
||||
todo o processo para todas as ferramentas do crewai-tools. Prefira `base_dir`.
|
||||
</Note>
|
||||
|
||||
Reference in New Issue
Block a user