Logo Sdk Php

Sdk Php

Tổ chứcPhổ biến
GetStream
sdk-php

How to build and extend the PHP SDK in sdks/php. Read this before changing the client, the generated DTOs, the Amp worker (dispatch, watch, realtime), folder sync, or before reaching for a dependency.

Tổng quan

Nhà phát hànhGetStream
Kho mãAgents
Tên kỹ năngsdk-php
Sao
8.2K
Bản fork
709
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được GetStream công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Sdk Php trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/GetStream/Agents/tree/main/.claude/skills/sdk-php
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/GetStream/Agents.git /tmp/Agents
mkdir -p .claude/skills
cp -r /tmp/Agents/.claude/skills/sdk-php .claude/skills/sdk-php
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Sdk Php trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Sdk Php ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Sdk Php với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

PHP SDK conventions

The per-language half of sdk, for the server side only. It records the decisions sdks/php already follows, so a change lands consistently rather than re-litigating them.

One Composer package, getstream/vision-agents, namespace GetStream\VisionAgents. PHP ^8.4, tested on 8.4 and 8.5. Strict types everywhere, final readonly classes, backed enums.

Layout

src/
  Client.php Backend.php Http.php Json.php     core: PSR-18 transport, auth, tolerant JSON
  Agent.php Session.php Sessions.php Responses.php Items.php AgentResponse.php AgentHandle.php
  Folder.php Folder/ Skill.php Harness.php Pipeline.php Tools.php Knowledge.php
  Edge.php Edge/StreamTransport.php Call.php   the Stream call, through getstream/getstream-php
  Router.php Router/                           search, recordings, realtime entry points
  Inbound/                                     InboundCall, InboundMessage
  Worker/                                      Amp only: Socket, Dispatch, Watch, Realtime
  Exception/
  Generated/                                   bin/generate.php output, never edited
bin/generate.php
tests/Unit tests/Live tests/Support tests/server/router.php

Why these choices

  • Name. getstream/vision-agents sits beside getstream/getstream-php on Packagist. Packagist needs composer.json at a repository root, so publishing is a git subtree split of sdks/php into its own repo from CI: .github/workflows/release-sdk-php.yml (see the release-sdks skill). Do not publish from the monorepo.
  • PHP 8.4. 8.3 left active support at the end of 2025; 8.4 gives new Foo()->bar(), property hooks if ever wanted, and is what the official images ship. Readonly classes and typed class constants need 8.3+ anyway.
  • PSR-18/17 plus php-http/discovery. A PHP app already owns an HTTP client (Guzzle, Symfony). Exposing Guzzle would force a version on them. Discovery finds whatever is installed; the constructor takes any client and factories. Discovery's Composer plugin is disabled (allow-plugins: false): it must never install packages behind a user's back.
  • Generation: a small in-repo generator, DTOs only. openapi-generator's php-nextgen is still beta and emits a Guzzle-bound client per operation; Jane is Symfony-shaped; Stainless is a hosted product. The spec is the router's own and uses a narrow subset of OpenAPI, so bin/generate.php (about 300 lines, Symfony Yaml) writes one final readonly class per object schema and one backed enum per enum schema, deterministic and diffable, with a --check mode for CI. Operations are not generated: Client has one method per HTTP verb, as in JS, and the hand-written resources hydrate the DTOs.
  • The core/worker split. A PHP web request is short-lived; a websocket is not. So the core (everything outside Worker/) is synchronous PSR-18 and has no event-loop dependency: it runs under FPM, Laravel, Symfony. Anything holding a socket (Session::watch, Dispatch, Router::*->realtime()) lives in Worker/ and needs amphp/websocket-client ^2 (Revolt, fibers), listed under suggest, never require. Amp over ReactPHP because it is fiber-based: handlers are plain blocking-looking code, and the same Client works inside and outside the loop.
  • Amp's PSR-18 adapter is preferred when installed (Http::client()), so an HTTP request made from a dispatch handler suspends its fiber instead of stalling every other call the worker holds. It is built with DnsSocketConnector (Amp's default connector retries a refused connection with backoff: a dead router took 18 s to fail) and a 120 s transfer timeout (opening a session returns only once the agent is in the call).
  • Stream's PHP SDK for calls. Edge uses getstream/getstream-php ^12.1 (VideoClient), sent through Edge\StreamTransport, an adapter over our PSR-18 client, so it too suspends in a worker, and tests point it at the local server. It needs a secret of 32+ bytes (firebase/php-jwt refuses shorter). Built lazily: an agent that only chats needs no Stream credentials.

Rules

  • Null means omit. Every optional DTO field is nullable and toArray() drops nulls. Never copy a schema default into PHP: the router or the stored config decides.
  • Tolerant reading. Json::* readers never throw on a missing or mistyped field. Enums are Enum|string: an unknown value is kept as the raw string, never refused. Date-times are DateTimeImmutable, fractional seconds cut to 6 digits (Go sends 9).
  • Errors. RouterException carries status (0 when nothing arrived), operation (METHOD /path), said (the envelope's error.message), body, retryAfter, and type, errorCode (not code: that is Exception's own integer), docUrl and requestId (X-Request-Id), all ?string. RouterException::answered builds every one from a response, HTTP and socket handshake alike; a body that is not the envelope (a proxy's HTML, empty, an older router's {"error": "..."} string) is said as it came, or the status text, with null type, code and doc URL. Local misuse is ConfigurationException, raised before a request. Socket error frames are RealtimeException; a failed recording job is RecordingFailedException.
  • Auth is Backend::headers(), minted per request. Server sockets send the same headers on the handshake, never credentials in the query string.
  • No reconnect. A dropped socket ends the iterator or run(); the owner decides. A frame that is not a JSON object, or of an unknown type, is skipped, never fatal.
  • Tool results repeat request_id and turn_id from the tool_call when present, or a durable command's result is refused. Tools run in their own fiber; a tool_cancel drops the answer (a PHP callable cannot be interrupted).
  • Dispatch sends active and handles on the handshake, answers every call and message with done and its work_id (an error when it failed or had no handler), answers a message with a session_id through answer, reports load {active_agents, latency_ms} after a ping/pong round trip, drains running handlers on exit, and traps SIGINT/SIGTERM only when pcntl is loaded (the official image has none). getOrCreateAgent holds a per-channel LocalKeyedMutex so two messages cannot start two agents.
  • Folder sync ports Go exactly. Folder::fingerprint is Go's fingerprint; with only a subagent and cost labels set, Agent::sync produces Go's hash (fmt.Sprint of a map is map[k:v ...], keys sorted). The fixture hash 02a7b2c8428f31e3a2b93ca2f5a6ec70 is pinned in FolderTest; if it moves, the port is wrong, not the pin. .agent_sync is {"hash","synced_at":"...+00:00"}; a matching stamp reads the stored config instead of syncing. Unknown agent.yaml keys are refused.
  • connectors: is read like Go's (Folder/Connector.php): a string is a session binding, an object {name, connector, tools, connection, required}; absent sends nothing, [] clears. A fixed connection is resolved through GET /v1/agents/connections (every page) at sync time. A non-empty plugins is refused (Declaration::refuseReplaced); an empty one loads.
  • Rewind takes a response id, never a turn_id, and answers 204. Fork takes responseId in ForkSessionRequest. A persisted conversation refuses rewind with 400.
  • responses->create() returns while the response is running. It does not wait; the live tests poll responses->list().
  • Realtime start frames nest options under the modality key ({"type":"start", "config_id":..., "stt":{...}}). The router reads only its own modality's block.
  • Comments state constraints only. Docblocks are short.

Testing

  • No mocks. Unit tests run against php -S executing tests/server/router.php, which answers from a JSON script and records every request; assertions are on what was sent. Socket tests run a real amphp/websocket-server on the same Revolt loop (tests/Support/LocalSocketServer), playing the router's side.
  • Live tests (tests/Live) are skipped unless VISION_AGENTS_URL is set; VISION_AGENTS_CUSTOMER_ID defaults to examples. Never start or restart the router for them.
  • PHPStan at level: max with phpstan-strict-rules, over src, tests and bin (tests/server excluded: it is a script for php -S).

Docker

The host has no PHP. Everything runs in the official images; nothing is installed on the host.

bash
docker run --rm -v "$PWD":/repo -v "$PWD/sdks/php/build/composer-cache":/tmp/composer-cache \
  -e COMPOSER_CACHE_DIR=/tmp/composer-cache -w /repo/sdks/php composer:2 install
docker run --rm -v "$PWD":/repo -w /repo/sdks/php php:8.4-cli vendor/bin/phpunit --testsuite unit
docker run --rm -v "$PWD":/repo -w /repo/sdks/php php:8.4-cli vendor/bin/phpstan analyse --memory-limit=1G
docker run --rm -v "$PWD":/repo -w /repo/sdks/php php:8.4-cli php bin/generate.php ../../acceleration/api/openapi.yaml --check
docker run --rm -v "$PWD":/repo -w /repo/sdks/php -e VISION_AGENTS_URL=http://host.docker.internal:8091 \
  php:8.4-cli vendor/bin/phpunit --testsuite live

Mount the repo root, not sdks/php: the generator reads ../../acceleration/api/openapi.yaml. composer:2 runs Composer (it has zip); php:8.4-cli and php:8.5-cli run the tests. The Composer cache lives in build/, which is gitignored. A custom Dockerfile was dropped when the Docker VM disk was full; do not prune shared images or volumes to make room.

After the spec changes

  1. php bin/generate.php ../../acceleration/api/openapi.yaml and review the diff.
  2. Hand-written resources only change for a new behaviour, not a new field.
  3. Unit tests, PHPStan, then the live suite once.
  4. Write the git ids of acceleration/api/openapi.yaml, .claude/skills/sdk/SKILL.md and .claude/skills/sdk/notes to sdks/php/.sdk_update_log, as the sdk skill's SDK updates section says, so the next update can diff what changed since.

Review checklist

  • A new optional field defaulted in PHP instead of left null.
  • An enum read with from() instead of tolerating unknown values.
  • A socket, event loop or Amp class referenced outside Worker/ (except the guarded Session::watch and Router entry points, which only construct worker objects).
  • A blocking sleep/usleep in code a worker calls (use Pause::for).
  • A mock, or an assertion on which method ran instead of what went over the wire.
  • agent.yaml handling that silently ignores a key.

Câu hỏi thường gặp

Kỹ năng AI Sdk Php làm được gì?

How to build and extend the PHP SDK in sdks/php. Read this before changing the client, the generated DTOs, the Amp worker (dispatch, watch, realtime), folder sync, or before reaching for a dependency.

Vì sao nên dùng Sdk Php trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Sdk Php là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Sdk Php trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/GetStream/Agents/tree/main/.claude/skills/sdk-php. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Sdk Php?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Sdk Php với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Sdk Php với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Sdk Php có miễn phí không?

Có. Kỹ năng này được GetStream phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇