# การใช้งานผ่านโค้ด (Programmatic Usage)

> คุณสามารถเรียกใช้งาน Foundry ผ่านโค้ดได้โดยอิมพอร์ตจาก Entry Point หลัก:

Source: https://bifrost5.com/th/foundry/docs/programmatic/

# การใช้งานผ่านโค้ด (Programmatic Usage)

Information

Use the AI tool you already pay for as a Foundry worker, through an MCP bridge, with Production-Grade.

[See editions](/th/foundry/docs/editions)

คุณสามารถเรียกใช้งาน Foundry ผ่านโค้ดได้โดยอิมพอร์ตจาก Entry Point หลัก:

```
import {
  controlLoop,
  loadState,
  enqueueTask,
  createQueue,
  type Task,
} from './index';
```

## ข้อจำกัดในการออกแบบ (Design Constraints)

- **สิทธิ์ขาดของผู้ควบคุม**: เฉพาะผู้ควบคุมเท่านั้นที่สามารถส่งเป้าหมายและงานเข้าสู่ระบบได้

- **การทำงานที่แน่นอนและคาดเดาได้ (Deterministic Execution)**: ควบคุมการทำงานด้วย Loop คงที่

- **การคงอยู่ของสถานะ (State Persistence)**: ทุกขั้นตอนจะได้รับการบันทึกไว้อย่างถาวร

- **การแยกสภาพแวดล้อม (Sandbox Isolation)**: แยกโปรเจกต์ออกจากกันในแต่ละโฟลเดอร์

- **การตรวจสอบย้อนหลัง (Audit Trail)**: มีบันทึกประวัติการตัดสินใจทั้งหมด

## เครื่องมือวินิจฉัยและสืบค้นปัญหา

```
# Check provider status and circuit breakers
npx ts-node scripts/investigations/provider-health.ts

# Inspect task queue and blocked tasks
npx ts-node scripts/investigations/task-queue-inspect.ts

# Analyze execution logs and error patterns
npx ts-node scripts/investigations/log-analyzer.ts --summary
```
