Adapters API¶
Optional adapters for external integrations.
Overview¶
AgentECS provides protocol-based adapters for common external services: - Vector Stores: Semantic search and RAG (ChromaDB) - LLM Clients: Structured output with multiple providers (Instructor) - Configuration: Type-safe settings with environment variables
Design Principles: - Optional dependencies: Don't require installation unless used - Protocol-based: Easy to implement custom adapters - Multi-provider: Support multiple backends per protocol - Type-safe: Generics ensure type safety throughout
Vector Store Adapter¶
Semantic search and retrieval-augmented generation.
VectorStore Protocol¶
VectorStore
¶
Bases: Protocol[T]
Protocol for vector database operations with typed data models.
Generic type T represents the data model (Pydantic model or dataclass) that will be stored alongside vectors.
Usage
@dataclass class Document: title: str content: str
store: VectorStore[Document] = ChromaAdapter.from_memory("docs", Document) store.add("doc1", embedding=[...], text="...", data=Document(...)) results = store.search(query_embedding=[...], mode=SearchMode.HYBRID)
Source code in src/agentecs/adapters/protocol.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
add(id, embedding, text, data)
¶
Add a single item to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Unique identifier for the item. |
required |
embedding
|
list[float]
|
Vector embedding. |
required |
text
|
str
|
Text content for keyword search. |
required |
data
|
T
|
Typed data model to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ID of the added item. |
Source code in src/agentecs/adapters/protocol.py
add_batch(items)
¶
Add multiple items to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
list[VectorStoreItem[T]]
|
List of items to add. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs for added items. |
get(id)
¶
Get an item by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Item identifier. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The data model if found, None otherwise. |
get_batch(ids)
¶
Get multiple items by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
List of item identifiers. |
required |
Returns:
| Type | Description |
|---|---|
list[T | None]
|
List of data models (None for missing items). |
update(id, embedding=None, text=None, data=None)
¶
Update an existing item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Item identifier. |
required |
embedding
|
list[float] | None
|
New embedding (optional). |
None
|
text
|
str | None
|
New text (optional). |
None
|
data
|
T | None
|
New data model (optional). |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if item existed and was updated. |
Source code in src/agentecs/adapters/protocol.py
delete(id)
¶
Delete an item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Item identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if item existed and was deleted. |
delete_batch(ids)
¶
Delete multiple items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
List of item identifiers. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of items deleted. |
search(query_embedding=None, query_text=None, mode=SearchMode.VECTOR, filters=None, limit=10)
¶
Search the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_embedding
|
list[float] | None
|
Query vector for vector/hybrid search. |
None
|
query_text
|
str | None
|
Query text for keyword/hybrid search. |
None
|
mode
|
SearchMode
|
Search mode (vector, keyword, or hybrid). |
VECTOR
|
filters
|
Filter | FilterGroup | None
|
Optional metadata filters. |
None
|
limit
|
int
|
Maximum number of results. |
10
|
Returns:
| Type | Description |
|---|---|
list[SearchResult[T]]
|
List of search results with scores. |
Source code in src/agentecs/adapters/protocol.py
ChromaDB Adapter¶
ChromaAdapter
¶
ChromaDB implementation of VectorStore protocol.
Stores typed data models (Pydantic or dataclass) with vector embeddings and supports hybrid search.
Attributes:
| Name | Type | Description |
|---|---|---|
collection |
Collection
|
The underlying ChromaDB collection. |
data_type |
type[T]
|
The type of data model being stored. |
Source code in src/agentecs/adapters/chroma.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
from_memory(collection_name, data_type)
classmethod
¶
Create adapter with ephemeral (in-memory) storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
Name of collection to use/create. |
required |
data_type
|
type[T]
|
Type of data model to store. |
required |
Returns:
| Type | Description |
|---|---|
ChromaAdapter[T]
|
Configured ChromaAdapter instance. |
Source code in src/agentecs/adapters/chroma.py
add(id, embedding, text, data)
¶
Add a single item to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Unique identifier for the item. |
required |
embedding
|
list[float]
|
Vector embedding. |
required |
text
|
str
|
Text content for keyword search. |
required |
data
|
T
|
Typed data model to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ID of the added item. |
Source code in src/agentecs/adapters/chroma.py
add_batch(items)
¶
Add multiple items to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
list[VectorStoreItem[T]]
|
List of items to add. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs for added items. |
Source code in src/agentecs/adapters/chroma.py
get(id)
¶
Get an item by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Item identifier. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The data model if found, None otherwise. |
Source code in src/agentecs/adapters/chroma.py
search(query_embedding=None, query_text=None, mode=SearchMode.VECTOR, filters=None, limit=10)
¶
Search the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_embedding
|
list[float] | None
|
Query vector for vector/hybrid search. |
None
|
query_text
|
str | None
|
Query text for keyword/hybrid search. |
None
|
mode
|
SearchMode
|
Search mode (vector, keyword, or hybrid). |
VECTOR
|
filters
|
Filter | FilterGroup | None
|
Optional metadata filters. |
None
|
limit
|
int
|
Maximum number of results. |
10
|
Returns:
| Type | Description |
|---|---|
list[SearchResult[T]]
|
List of search results with scores. |
Source code in src/agentecs/adapters/chroma.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
Models¶
SearchMode
¶
SearchResult
dataclass
¶
Result from a vector store search.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Document identifier. |
data |
T
|
The typed data model. |
score |
float
|
Similarity/relevance score (higher is better, normalized 0-1 for cosine). |
distance |
float | None
|
Raw distance value (lower is better). |
Source code in src/agentecs/adapters/models.py
VectorStoreItem
dataclass
¶
Item to add to vector store.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the item. |
embedding |
list[float]
|
Vector embedding. |
text |
str
|
Text content for keyword search. |
data |
T
|
The typed data model to store. |
Source code in src/agentecs/adapters/models.py
Filter
dataclass
¶
Single filter condition.
Attributes:
| Name | Type | Description |
|---|---|---|
field |
str
|
Field name to filter on (supports nested: "metadata.category"). |
operator |
FilterOperator
|
Comparison operator. |
value |
Any
|
Value to compare against. |
Source code in src/agentecs/adapters/models.py
FilterGroup
dataclass
¶
Group of filters combined with AND/OR.
Attributes:
| Name | Type | Description |
|---|---|---|
filters |
list[Filter | FilterGroup]
|
List of Filter or nested FilterGroup. |
operator |
str
|
How to combine filters ("and" or "or"). |
Source code in src/agentecs/adapters/models.py
LLM Client Adapter¶
Structured LLM output with multiple providers.
LLMClient Protocol¶
LLMClient
¶
Bases: Protocol
Protocol for LLM operations with structured output.
Uses Pydantic models for type-safe responses.
Usage
class Analysis(BaseModel): sentiment: str confidence: float
client: LLMClient = InstructorAdapter.from_openai_client(openai_client) result: Analysis = client.call(messages, response_model=Analysis)
Source code in src/agentecs/adapters/protocol.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
call(messages, response_model, temperature=None, max_tokens=None, **kwargs)
¶
Call LLM with structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Validated response as the specified model type. |
Source code in src/agentecs/adapters/protocol.py
call_async(messages, response_model, temperature=None, max_tokens=None, **kwargs)
async
¶
Call LLM with structured output (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Validated response as the specified model type. |
Source code in src/agentecs/adapters/protocol.py
stream(messages, response_model, temperature=None, max_tokens=None, **kwargs)
¶
Stream LLM response with partial structured output.
Yields partial objects as they are received, with fields populated incrementally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters. |
{}
|
Yields:
| Type | Description |
|---|---|
T
|
Partial response objects with incrementally populated fields. |
Source code in src/agentecs/adapters/protocol.py
stream_async(messages, response_model, temperature=None, max_tokens=None, **kwargs)
¶
Stream LLM response with partial structured output (async).
Yields partial objects as they are received, with fields populated incrementally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[T]
|
Partial response objects with incrementally populated fields. |
Source code in src/agentecs/adapters/protocol.py
Instructor Adapter¶
InstructorAdapter
¶
Instructor-based implementation of LLMClient protocol.
Uses instructor library for structured LLM output with Pydantic models.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
The instructor-patched client. |
|
settings |
LLMSettings
|
LLM configuration settings. |
Source code in src/agentecs/adapters/instructor.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
from_openai_client(client, settings=None, async_client=None, mode=None)
classmethod
¶
Create adapter from OpenAI client.
Wraps the OpenAI client with instructor for structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
OpenAI
|
OpenAI client instance. |
required |
settings
|
LLMSettings | None
|
Optional LLM settings. |
None
|
async_client
|
AsyncOpenAI | None
|
Optional async OpenAI client. |
None
|
mode
|
Mode | None
|
Instructor mode (default: TOOLS). |
None
|
Returns:
| Type | Description |
|---|---|
InstructorAdapter
|
Configured InstructorAdapter instance. |
Source code in src/agentecs/adapters/instructor.py
from_anthropic(client, settings=None, async_client=None, mode=None)
classmethod
¶
Create adapter from Anthropic client.
Wraps the Anthropic client with instructor for structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Any
|
anthropic.Anthropic client instance. |
required |
settings
|
LLMSettings | None
|
Optional LLM settings. |
None
|
async_client
|
Any | None
|
Optional anthropic.AsyncAnthropic client. |
None
|
mode
|
Any | None
|
instructor.Mode (default: ANTHROPIC_TOOLS). |
None
|
Returns:
| Type | Description |
|---|---|
InstructorAdapter
|
Configured InstructorAdapter instance. |
Example
Source code in src/agentecs/adapters/instructor.py
from_litellm(settings=None, mode=None)
classmethod
¶
Create adapter using LiteLLM for multi-provider support.
LiteLLM provides a unified interface to 100+ LLM providers including OpenAI, Anthropic, Cohere, Azure, AWS Bedrock, and more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
LLMSettings | None
|
Optional LLM settings. The model field should use LiteLLM's provider/model format (e.g., "anthropic/claude-3-opus"). |
None
|
mode
|
Any | None
|
Instructor mode (default: TOOLS). |
None
|
Returns:
| Type | Description |
|---|---|
InstructorAdapter
|
Configured InstructorAdapter instance. |
Example
from agentecs.adapters import InstructorAdapter
from agentecs.config import LLMSettings
# Use Claude via LiteLLM
adapter = InstructorAdapter.from_litellm(
settings=LLMSettings(model="anthropic/claude-3-5-sonnet-20241022")
)
# Use GPT-4 via LiteLLM
adapter = InstructorAdapter.from_litellm(
settings=LLMSettings(model="openai/gpt-4o")
)
Source code in src/agentecs/adapters/instructor.py
from_gemini(client, settings=None, mode=None)
classmethod
¶
Create adapter from Google Gemini client.
Wraps the Google GenerativeModel with instructor for structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Any
|
Google GenerativeModel instance. |
required |
settings
|
LLMSettings | None
|
Optional LLM settings. |
None
|
mode
|
Any | None
|
Instructor mode (default: GEMINI_JSON). |
None
|
Returns:
| Type | Description |
|---|---|
InstructorAdapter
|
Configured InstructorAdapter instance. |
Example
Source code in src/agentecs/adapters/instructor.py
call(messages, response_model, temperature=None, max_tokens=None, **kwargs)
¶
Call LLM with structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Validated response as the specified model type. |
Source code in src/agentecs/adapters/instructor.py
call_async(messages, response_model, temperature=None, max_tokens=None, **kwargs)
async
¶
Call LLM with structured output (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Validated response as the specified model type. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no async client was provided. |
Source code in src/agentecs/adapters/instructor.py
stream(messages, response_model, temperature=None, max_tokens=None, **kwargs)
¶
Stream LLM response with partial structured output.
Uses instructor's Partial for incremental field population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Yields:
| Type | Description |
|---|---|
T
|
Partial response objects with incrementally populated fields. |
Source code in src/agentecs/adapters/instructor.py
stream_async(messages, response_model, temperature=None, max_tokens=None, **kwargs)
async
¶
Stream LLM response with partial structured output (async).
Uses instructor's Partial for incremental field population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation messages. |
required |
response_model
|
type[T]
|
Pydantic model for response validation. |
required |
temperature
|
float | None
|
Override default temperature. |
None
|
max_tokens
|
int | None
|
Override default max tokens. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[T]
|
Partial response objects with incrementally populated fields. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no async client was provided. |
Source code in src/agentecs/adapters/instructor.py
Models¶
Message
dataclass
¶
A message in an LLM conversation.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
MessageRole
|
Who sent the message. |
content |
str
|
Message text content. |
Source code in src/agentecs/adapters/models.py
MessageRole
¶
Configuration¶
Type-safe configuration with Pydantic Settings.
VectorStoreSettings
¶
Bases: BaseSettings
Configuration for vector store adapters.
Attributes:
| Name | Type | Description |
|---|---|---|
collection_name |
str
|
Name of the collection/index. |
persist_directory |
str | None
|
Path for persistent storage (None for ephemeral). |
distance_metric |
str
|
Distance function for similarity (cosine, l2, ip). |
Environment Variables
VECTORSTORE_COLLECTION_NAME VECTORSTORE_PERSIST_DIRECTORY VECTORSTORE_DISTANCE_METRIC
Source code in src/agentecs/config/settings.py
LLMSettings
¶
Bases: BaseSettings
Configuration for LLM adapters.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
Model name/identifier. |
temperature |
float
|
Sampling temperature (0.0-2.0). |
max_tokens |
int | None
|
Maximum tokens in response. |
api_key |
str | None
|
API key (prefer environment variable). |
base_url |
str | None
|
Custom API base URL (for proxies/local models). |
timeout |
float
|
Request timeout in seconds. |
max_retries |
int
|
Number of retries on failure. |
Environment Variables
LLM_MODEL LLM_TEMPERATURE LLM_MAX_TOKENS LLM_API_KEY (or OPENAI_API_KEY as fallback) LLM_BASE_URL LLM_TIMEOUT LLM_MAX_RETRIES
Source code in src/agentecs/config/settings.py
Installation¶
Install adapter dependencies:
# Vector store adapter
pip install agentecs[vector]
# LLM adapter
pip install agentecs[llm]
# Configuration
pip install agentecs[config]
# All adapters
pip install agentecs[all]
Usage Examples¶
Vector Store¶
from pydantic import BaseModel
from agentecs.adapters import ChromaAdapter, SearchMode
class Document(BaseModel):
title: str
content: str
# Create adapter
store = ChromaAdapter.from_memory("docs", Document)
# Add documents
store.add("doc1", embedding=[...], text="content", data=Document(...))
# Search
results = store.search(
query_embedding=[...],
mode=SearchMode.HYBRID,
limit=10
)
LLM Client¶
from pydantic import BaseModel
from agentecs.adapters import InstructorAdapter, Message
from agentecs.config import LLMSettings
class Analysis(BaseModel):
sentiment: str
confidence: float
# Create adapter
adapter = InstructorAdapter.from_litellm(
settings=LLMSettings(model="anthropic/claude-3-5-sonnet-20241022")
)
# Call with structured output
messages = [Message.user("Analyze: Great product!")]
result = adapter.call(messages, response_model=Analysis)