Was this page helpful?
Files API를 통해 파일을 업로드하고 세션의 컨테이너에 마운트하여 에이전트에 파일을 제공할 수 있습니다.
모든 Managed Agents API 요청에는 managed-agents-2026-04-01 베타 헤더가 필요합니다. SDK는 베타 헤더를 자동으로 설정합니다.
먼저 Files API를 사용하여 파일을 업로드합니다:
file = client.beta.files.upload(file=Path("data.csv"))
print(f"File ID: {file.id}")세션을 생성할 때 resources 배열에 업로드된 파일을 추가하여 컨테이너에 마운트합니다:
mount_path는 선택 사항이지만, 업로드된 파일에 설명적인 이름이 있는지 확인하여 에이전트가 찾고 있는 파일을 알 수 있도록 하세요.
세션의 파일 인스턴스를 참조하는 새로운 file_id가 생성됩니다. 이러한 복사본은 저장소 제한에 포함되지 않습니다.
resources 배열에 항목을 추가하여 여러 파일을 마운트합니다:
세션당 최대 100개의 파일이 지원됩니다.
세션 리소스 API를 사용하여 생성 후 세션에서 파일을 추가하거나 제거할 수 있습니다. 각 리소스에는 추가(또는 나열)될 때 반환되는 id가 있으며, 이를 삭제할 때 사용합니다.
resources.list로 세션의 모든 리소스를 나열합니다. 파일을 제거하려면 리소스 ID와 함께 resources.delete를 호출합니다:
Files API를 사용하여 세션으로 범위가 지정된 파일을 나열하고 다운로드합니다.
에이전트는 다음을 포함한 모든 파일 유형으로 작업할 수 있습니다:
.py, .js, .ts, .go, .rs 등).csv, .json, .xml, .yaml).txt, .md).zip, .tar.gz) - 에이전트는 bash를 사용하여 이를 추출할 수 있습니다컨테이너에 마운트된 파일은 읽기 전용 복사본입니다. 에이전트는 이를 읽을 수 있지만 원본 업로드된 파일을 수정할 수 없습니다. 수정된 버전으로 작업하려면 에이전트는 컨테이너 내의 새 경로에 씁니다.
/로 시작)session = client.beta.sessions.create(
agent=agent.id,
environment_id=environment.id,
resources=[
{
"type": "file",
"file_id": file.id,
"mount_path": "/workspace/data.csv",
},
],
)resources = [
{"type": "file", "file_id": "file_abc123", "mount_path": "/workspace/data.csv"},
{"type": "file", "file_id": "file_def456", "mount_path": "/workspace/config.json"},
{"type": "file", "file_id": "file_ghi789", "mount_path": "/workspace/src/main.py"},
]resource = client.beta.sessions.resources.add(
session.id,
type="file",
file_id=file.id,
)
print(resource.id) # "sesrsc_01ABC..."listed = client.beta.sessions.resources.list(session.id)
for entry in listed.data:
print(entry.id, entry.type)
client.beta.sessions.resources.delete(resource.id, session_id=session.id)# List files associated with a session
files = client.beta.files.list(
scope_id="sesn_abc123",
betas=["managed-agents-2026-04-01"],
)
for f in files:
print(f.id, f.filename)
# Download a file
content = client.beta.files.download(files.data[0].id)
content.write_to_file("output.txt")