Skip to content

Commit 1715417

Browse files
committed
Add API reference sections to documentation
Introduced detailed API reference sections to all major capability and core concept documentation pages, including chat, embeddings, images, speech, streaming, structured output, text, agents, pipelines, system prompts, and tools. These sections provide concise overviews of available methods, fluent APIs, response properties, and common usage patterns to improve developer experience and discoverability.
1 parent c8810c0 commit 1715417

File tree

16 files changed

+720
-17
lines changed

16 files changed

+720
-17
lines changed

docs/advanced/custom-providers.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,47 @@ Atlas::agent('my-agent')
9292
->chat('Hello');
9393
```
9494

95+
## API Reference
96+
97+
```php
98+
// Agent provider configuration (override in agent class)
99+
public function provider(): ?string; // Provider name (e.g., 'openai', 'anthropic')
100+
public function model(): ?string; // Model name (e.g., 'gpt-4o', 'claude-sonnet-4-20250514')
101+
public function clientOptions(): array; // HTTP client options
102+
public function providerOptions(): array; // Provider-specific options
103+
104+
// Runtime provider override
105+
Atlas::agent('agent')
106+
->withProvider(string $provider, ?string $model = null) // Override provider and optionally model
107+
->withModel(string $model) // Override model only
108+
->withProviderOptions(array $options) // Provider-specific options
109+
->chat(string $input);
110+
111+
// Direct Prism usage with providers
112+
Atlas::text()->using(string $provider, string $model);
113+
Atlas::image()->using(string $provider, string $model);
114+
Atlas::audio()->using(string $provider, string $model);
115+
Atlas::embeddings()->using(string $provider, string $model);
116+
Atlas::moderation()->using(string $provider, string $model);
117+
118+
// Provider-specific options (via withProviderMeta or withProviderOptions)
119+
// Anthropic:
120+
->withProviderOptions(['cacheType' => 'ephemeral']) // Prompt caching
121+
122+
// OpenAI:
123+
->withProviderOptions([
124+
'presence_penalty' => 0.5, // -2.0 to 2.0
125+
'frequency_penalty' => 0.3, // -2.0 to 2.0
126+
'logit_bias' => [], // Token biases
127+
'user' => 'user-123', // End-user identifier
128+
])
129+
130+
// Provider resolution order:
131+
// 1. withProvider() override (highest priority)
132+
// 2. Agent's provider() method
133+
// 3. Exception if neither set
134+
```
135+
95136
## Next Steps
96137

97138
- [Chat](/capabilities/chat) — Chat configuration

docs/advanced/error-handling.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,66 @@ class ChatController extends Controller
225225
}
226226
```
227227

228+
## API Reference
229+
230+
```php
231+
// Atlas exception hierarchy
232+
use Atlasphp\Atlas\Exceptions\AtlasException;
233+
use Atlasphp\Atlas\Agents\Exceptions\AgentException;
234+
use Atlasphp\Atlas\Agents\Exceptions\AgentNotFoundException;
235+
use Atlasphp\Atlas\Agents\Exceptions\InvalidAgentException;
236+
use Atlasphp\Atlas\Tools\Exceptions\ToolException;
237+
use Atlasphp\Atlas\Tools\Exceptions\ToolNotFoundException;
238+
239+
// Base exception - catch all Atlas errors
240+
try {
241+
$response = Atlas::agent('agent')->chat('Hello');
242+
} catch (AtlasException $e) {
243+
// Any Atlas configuration error
244+
}
245+
246+
// Agent exceptions
247+
try {
248+
$response = Atlas::agent('unknown')->chat('Hello');
249+
} catch (AgentNotFoundException $e) {
250+
$e->getMessage(); // "No agent found with key 'unknown'."
251+
} catch (InvalidAgentException $e) {
252+
$e->getMessage(); // Invalid agent configuration
253+
} catch (AgentException $e) {
254+
// Any agent-related error
255+
}
256+
257+
// Tool exceptions
258+
try {
259+
$tool = $registry->get('unknown_tool');
260+
} catch (ToolNotFoundException $e) {
261+
$e->getMessage(); // "Tool not found: unknown_tool"
262+
} catch (ToolException $e) {
263+
// Any tool-related error
264+
}
265+
266+
// ToolResult for tool error handling (don't throw, return errors)
267+
use Atlasphp\Atlas\Tools\Support\ToolResult;
268+
269+
ToolResult::text(string $text): ToolResult; // Success with text
270+
ToolResult::json(array $data): ToolResult; // Success with JSON
271+
ToolResult::error(string $message): ToolResult; // Error result
272+
273+
$result->succeeded(): bool; // Check if successful
274+
$result->failed(): bool; // Check if failed
275+
276+
// Prism exceptions (pass through Atlas)
277+
// See: https://prismphp.com/advanced/error-handling.html
278+
use Prism\Prism\Exceptions\PrismException;
279+
use Prism\Prism\Exceptions\PrismRateLimitException;
280+
use Prism\Prism\Exceptions\PrismContextLengthExceededException;
281+
282+
// Retry configuration (via Prism passthrough)
283+
Atlas::agent('agent')
284+
->withClientRetry(int $times, int $sleepMs) // Automatic retries
285+
->chat('Hello');
286+
```
287+
228288
## Next Steps
229289

230290
- [Pipelines](/core-concepts/pipelines) — Add error handling middleware

docs/advanced/testing.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,75 @@ public function test_handles_provider_errors(): void
511511
</groups>
512512
```
513513

514+
## API Reference
515+
516+
```php
517+
// Enabling fake mode
518+
$fake = Atlas::fake(); // Returns AtlasFake instance
519+
$fake = Atlas::fake([PrismResponse $response]); // With default response
520+
521+
// Configuring fake responses
522+
$fake->response(string $agentKey): PendingFakeRequest;
523+
$fake->response(string $agentKey, PrismResponse $response): AtlasFake;
524+
$fake->sequence(array $responses): AtlasFake; // Default sequence for any agent
525+
$fake->preventStrayRequests(): AtlasFake; // Fail on unconfigured agents
526+
$fake->allowStrayRequests(): AtlasFake; // Allow unconfigured agents
527+
$fake->reset(): AtlasFake; // Clear recorded requests
528+
529+
// PendingFakeRequest fluent API
530+
$fake->response('agent-key')
531+
->return(PrismResponse $response): AtlasFake;
532+
->returnSequence(array $responses): AtlasFake;
533+
->throw(Throwable $exception): AtlasFake;
534+
->whenEmpty(PrismResponse|Throwable $response): PendingFakeRequest;
535+
536+
// Creating fake Prism responses
537+
use Prism\Prism\Text\Response as PrismResponse;
538+
use Prism\Prism\ValueObjects\Usage;
539+
use Prism\Prism\Enums\FinishReason;
540+
541+
// Simple text response
542+
new PrismResponse(
543+
text: 'Hello! How can I help?',
544+
finishReason: FinishReason::Stop,
545+
usage: new Usage(promptTokens: 10, completionTokens: 20),
546+
);
547+
548+
// Assertion methods
549+
$fake->assertCalled(): void; // Any agent called
550+
$fake->assertCalled(string $agentKey): void; // Specific agent called
551+
$fake->assertCalledTimes(string $agentKey, int $times): void;
552+
$fake->assertNotCalled(string $agentKey): void;
553+
$fake->assertNothingCalled(): void;
554+
$fake->assertSent(Closure $callback): void; // Custom assertion
555+
$fake->assertSentWithContext(string $key, mixed $value = null): void;
556+
$fake->assertSentWithSchema(): void;
557+
$fake->assertSentWithInput(string $needle): void;
558+
559+
// Accessing recorded requests
560+
$fake->recorded(): array; // All RecordedRequest objects
561+
$fake->recordedFor(string $agentKey): array; // For specific agent
562+
563+
// RecordedRequest properties and methods
564+
$request->agent; // AgentContract instance
565+
$request->input; // User input string
566+
$request->context; // ExecutionContext
567+
$request->response; // PrismResponse
568+
$request->timestamp; // Unix timestamp
569+
$request->agentKey(): string;
570+
$request->inputContains(string $needle): bool;
571+
$request->hasMetadata(string $key, mixed $value = null): bool;
572+
$request->hasPrismCall(string $method): bool;
573+
$request->getPrismCallArgs(string $method): ?array;
574+
575+
// Cleanup
576+
Atlas::unfake(); // Restore real executor
577+
$fake->restore(); // Alternative restore method
578+
579+
// Auto-cleanup trait
580+
use Atlasphp\Atlas\Testing\Concerns\InteractsWithAtlasFake;
581+
```
582+
514583
## Next Steps
515584

516585
- [Agents](/core-concepts/agents) — Build testable agents

docs/capabilities/chat.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,80 @@ if ($response->text !== null) {
276276

277277
See [Prism Response](https://prismphp.com/core-concepts/text-generation.html#the-response-object) for the complete response API.
278278

279+
## API Reference
280+
281+
```php
282+
// Agent chat fluent API
283+
Atlas::agent(string|AgentContract $agent)
284+
// Context configuration
285+
->withMessages(array $messages) // Conversation history
286+
->withVariables(array $variables) // System prompt variables
287+
->withMetadata(array $metadata) // Pipeline/tool metadata
288+
289+
// Provider overrides
290+
->withProvider(string $provider, ?string $model) // Override provider/model
291+
->withModel(string $model) // Override model only
292+
293+
// Attachments
294+
->withMedia(Image|Document|Audio|Video|array $media) // Attach media (builder style)
295+
296+
// Structured output
297+
->withSchema(SchemaBuilder|ObjectSchema $schema) // Schema for structured response
298+
->usingAutoMode() // Auto schema mode (default)
299+
->usingNativeMode() // Native JSON schema mode
300+
->usingJsonMode() // JSON mode (for optional fields)
301+
302+
// Prism passthrough methods
303+
->withToolChoice(ToolChoice $choice) // Tool selection (Auto, Any, None)
304+
->withMaxTokens(int $tokens) // Max response tokens
305+
->withTemperature(float $temp) // Sampling temperature
306+
->usingTopP(float $topP) // Top-p sampling
307+
->usingTopK(int $topK) // Top-k sampling
308+
->withClientRetry(int $times, int $sleepMs) // Retry with backoff
309+
->withClientOptions(array $options) // HTTP client options
310+
->withProviderOptions(array $options) // Provider-specific options
311+
312+
// Execution
313+
->chat(string $input, array $attachments = []): PrismResponse|StructuredResponse;
314+
->stream(string $input, array $attachments = []): Generator<StreamEvent>;
315+
316+
// Response properties (PrismResponse)
317+
$response->text; // Generated text
318+
$response->usage->promptTokens; // Input tokens
319+
$response->usage->completionTokens; // Output tokens
320+
$response->steps; // Multi-step agentic loop history
321+
$response->toolCalls; // Tool calls made
322+
$response->toolResults; // Tool execution results
323+
$response->finishReason; // FinishReason enum
324+
$response->meta; // Request metadata
325+
326+
// Response properties (StructuredResponse - when using withSchema)
327+
$response->structured; // Extracted structured data array
328+
$response->text; // Raw text (if available)
329+
$response->usage; // Token usage stats
330+
331+
// Message formats for withMessages()
332+
// Array format (for persistence):
333+
[
334+
['role' => 'user', 'content' => 'Hello'],
335+
['role' => 'assistant', 'content' => 'Hi there!'],
336+
]
337+
338+
// Prism message objects (for full API access):
339+
[
340+
new UserMessage('Hello'),
341+
new AssistantMessage('Hi there!'),
342+
]
343+
344+
// Prism media objects for attachments
345+
Image::fromUrl(string $url): Image;
346+
Image::fromLocalPath(string $path): Image;
347+
Image::fromBase64(string $data, string $mimeType): Image;
348+
Image::fromStoragePath(string $path, string $mimeType, ?string $disk): Image;
349+
Image::fromFileId(string $fileId): Image;
350+
// Same methods available on Document, Audio, Video
351+
```
352+
279353
## Next Steps
280354

281355
- [Streaming](/capabilities/streaming) — Real-time streaming responses

docs/capabilities/embeddings.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ foreach ($response->embeddings as $index => $vector) {
3939
}
4040
```
4141

42-
## Semantic Search Example
42+
## Example: Semantic Search
4343

4444
```php
4545
// Index documents
@@ -69,7 +69,7 @@ $results = Document::query()
6969
->get();
7070
```
7171

72-
## RAG Implementation
72+
## Example: RAG Implementation
7373

7474
Combine embeddings with agents for retrieval-augmented generation:
7575

@@ -197,6 +197,38 @@ class LogEmbeddings implements PipelineContract
197197
$registry->register('embeddings.after_embeddings', LogEmbeddings::class);
198198
```
199199

200+
## API Reference
201+
202+
```php
203+
// Embeddings fluent API
204+
Atlas::embeddings()
205+
->using(string $provider, string $model) // Set provider and model
206+
->fromInput(string|array $input) // Text(s) to embed
207+
->withProviderMeta(string $provider, array $options) // Provider-specific options
208+
->withMetadata(array $metadata) // Pipeline metadata
209+
->asEmbeddings(): EmbeddingsResponse;
210+
211+
// Response properties (EmbeddingsResponse)
212+
$response->embeddings; // array of embedding vectors
213+
$response->embeddings[0]; // First embedding (array of floats)
214+
$response->usage->tokens; // Tokens used
215+
216+
// Common models
217+
->using('openai', 'text-embedding-3-small') // 1536 dimensions, cheaper
218+
->using('openai', 'text-embedding-3-large') // 3072 dimensions, more accurate
219+
->using('openai', 'text-embedding-ada-002') // 1536 dimensions, legacy
220+
221+
// Single vs batch input
222+
->fromInput('Single text to embed')
223+
->fromInput(['Text one', 'Text two', 'Text three']) // Batch (more efficient)
224+
225+
// Provider options (via withProviderMeta)
226+
->withProviderMeta('openai', [
227+
'dimensions' => 512, // Reduce dimensions (text-embedding-3-* only)
228+
'encoding_format' => 'float' // 'float' or 'base64'
229+
])
230+
```
231+
200232
## Next Steps
201233

202234
- [Prism Embeddings](https://prismphp.com/core-concepts/embeddings.html) — Complete embeddings reference

docs/capabilities/images.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Storage::put('images/lake.png', $imageContent);
4646
Http::sink(storage_path('images/lake.png'))->get($response->images[0]->url);
4747
```
4848

49-
## Complete Example
49+
## Example: Complete Image Generation
5050

5151
```php
5252
use Atlasphp\Atlas\Atlas;
@@ -110,6 +110,38 @@ class LogImageGeneration implements PipelineContract
110110
$registry->register('image.after_generate', LogImageGeneration::class);
111111
```
112112

113+
## API Reference
114+
115+
```php
116+
// Image generation fluent API
117+
Atlas::image()
118+
->using(string $provider, string $model) // Set provider and model
119+
->withPrompt(string $prompt) // Image description
120+
->withSize(int $width, int $height) // Image dimensions
121+
->withProviderMeta(string $provider, array $options) // Provider-specific options
122+
->withMetadata(array $metadata) // Pipeline metadata
123+
->generate(): ImageResponse;
124+
125+
// Response properties (ImageResponse)
126+
$response->images; // array of Image objects
127+
$response->images[0]->url; // URL to generated image
128+
$response->images[0]->base64; // Base64 encoded image (if requested)
129+
$response->images[0]->revisedPrompt; // Revised prompt (if modified by provider)
130+
131+
// Common provider options (via withProviderMeta)
132+
// OpenAI DALL-E 3:
133+
->withProviderMeta('openai', [
134+
'quality' => 'standard', // 'standard' or 'hd'
135+
'style' => 'vivid', // 'vivid' or 'natural'
136+
'response_format' => 'url', // 'url' or 'b64_json'
137+
])
138+
139+
// Common sizes
140+
->withSize(1024, 1024) // Square (DALL-E 3)
141+
->withSize(1792, 1024) // Landscape (DALL-E 3)
142+
->withSize(1024, 1792) // Portrait (DALL-E 3)
143+
```
144+
113145
## Next Steps
114146

115147
- [Prism Image Generation](https://prismphp.com/core-concepts/image-generation.html) — Complete image reference

0 commit comments

Comments
 (0)