PotatoHead
Agent
¶
Source code in python/potato_head/_potato_head.pyi
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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
|
id
property
¶
The ID of the agent. This is a random uuid7 that is generated when the agent is created.
system_instruction
property
¶
The system message to use for the agent. This is a list of Message objects.
__init__(provider, system_instruction=None)
¶
Create an Agent object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
Provider | str
|
The provider to use for the agent. This can be a Provider enum or a string representing the provider. |
required |
system_instruction
|
Optional[str | List[str] | Message | List[Message]]
|
The system message to use for the agent. This can be a string, a list of strings, a Message object, or a list of Message objects. If None, no system message will be used. This is added to all tasks that the agent executes. If a given task contains it's own system message, the agent's system message will be prepended to the task's system message. |
None
|
Example:
Source code in python/potato_head/_potato_head.pyi
execute_prompt(prompt, output_type=None, model=None)
¶
Execute a prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Prompt
|
` The prompt to execute. |
required |
output_type
|
Optional[Any]
|
The output type to use for the task. This can either be a Pydantic |
None
|
model
|
Optional[str]
|
The model to use for the task. If not provided, defaults to the |
None
|
Returns:
Name | Type | Description |
---|---|---|
AgentResponse |
AgentResponse
|
The response from the agent after executing the task. |
Source code in python/potato_head/_potato_head.pyi
execute_task(task, output_type=None, model=None)
¶
Execute a task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Task
|
The task to execute. |
required |
output_type
|
Optional[Any]
|
The output type to use for the task. This can either be a Pydantic |
None
|
model
|
Optional[str]
|
The model to use for the task. If not provided, defaults to the |
None
|
Returns:
Name | Type | Description |
---|---|---|
AgentResponse |
AgentResponse
|
The response from the agent after executing the task. |
Source code in python/potato_head/_potato_head.pyi
AgentResponse
¶
Source code in python/potato_head/_potato_head.pyi
id
property
¶
The ID of the agent response.
log_probs
property
¶
Returns the log probabilities of the agent response if supported. This is primarily used for debugging and analysis purposes.
result
property
¶
The result of the agent response. This can be a Pydantic BaseModel class or a supported potato_head response type such as Score
.
If neither is provided, the response json will be returned as a dictionary.
token_usage
property
¶
Returns the token usage of the agent response if supported
AudioUrl
¶
Source code in python/potato_head/_potato_head.pyi
format
property
¶
The format of the audio URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the audio URL.
url
property
¶
The URL of the audio.
__init__(url, kind='audio-url')
¶
Create an AudioUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the audio. |
required |
kind
|
Literal['audio-url']
|
The kind of the content. |
'audio-url'
|
Source code in python/potato_head/_potato_head.pyi
BinaryContent
¶
Source code in python/potato_head/_potato_head.pyi
data
property
¶
The binary data.
format
property
¶
The format of the binary content.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the binary content.
__init__(data, media_type, kind='binary')
¶
Create a BinaryContent object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
bytes
|
The binary data. |
required |
media_type
|
str
|
The media type of the binary data. |
required |
kind
|
str
|
The kind of the content |
'binary'
|
Source code in python/potato_head/_potato_head.pyi
CompletionTokenDetails
¶
Details about the completion tokens used in a model response.
Source code in python/potato_head/_potato_head.pyi
accepted_prediction_tokens
property
¶
The number of accepted prediction tokens used in the response.
audio_tokens
property
¶
The number of audio tokens used in the response.
reasoning_tokens
property
¶
The number of reasoning tokens used in the response.
rejected_prediction_tokens
property
¶
The number of rejected prediction tokens used in the response.
DocumentUrl
¶
Source code in python/potato_head/_potato_head.pyi
format
property
¶
The format of the document URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the document URL.
url
property
¶
The URL of the document.
__init__(url, kind='document-url')
¶
Create a DocumentUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the document. |
required |
kind
|
Literal['document-url']
|
The kind of the content. |
'document-url'
|
Source code in python/potato_head/_potato_head.pyi
Embedder
¶
Class for creating embeddings.
Source code in python/potato_head/_potato_head.pyi
__init__(provider, config=None)
¶
Create an Embedder object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
Provider | str
|
The provider to use for the embedder. This can be a Provider enum or a string representing the provider. |
required |
config
|
Optional[OpenAIEmbeddingConfig | GeminiEmbeddingConfig]
|
The configuration to use for the embedder. This can be a Pydantic BaseModel class representing the configuration for the provider. If no config is provided, defaults to OpenAI provider configuration. |
None
|
Source code in python/potato_head/_potato_head.pyi
embed(input)
¶
Create embeddings for input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str | List[str] | PredictRequest
|
The input to embed. Type depends on provider: - OpenAI/Gemini: str | List[str] - Vertex: PredictRequest |
required |
Returns:
Type | Description |
---|---|
OpenAIEmbeddingResponse | GeminiEmbeddingResponse | PredictResponse
|
Provider-specific response type. |
OpenAIEmbeddingResponse | GeminiEmbeddingResponse | PredictResponse
|
OpenAIEmbeddingResponse for OpenAI, |
OpenAIEmbeddingResponse | GeminiEmbeddingResponse | PredictResponse
|
GeminiEmbeddingResponse for Gemini, |
OpenAIEmbeddingResponse | GeminiEmbeddingResponse | PredictResponse
|
PredictResponse for Vertex. |
Examples:
## OpenAI
embedder = Embedder(Provider.OpenAI)
response = embedder.embed(input="Test input")
## Gemini
embedder = Embedder(Provider.Gemini, config=GeminiEmbeddingConfig(model="gemini-embedding-001"))
response = embedder.embed(input="Test input")
## Vertex
from potato_head.google import PredictRequest
embedder = Embedder(Provider.Vertex)
response = embedder.embed(input=PredictRequest(text="Test input"))
Source code in python/potato_head/_potato_head.pyi
EventDetails
¶
Source code in python/potato_head/_potato_head.pyi
duration
property
¶
The duration of the task execution.
end_time
property
¶
The end time of the task execution.
error
property
¶
The error message if the task failed, otherwise None.
prompt
property
¶
The prompt used for the task.
response
property
¶
The response from the agent after executing the task.
start_time
property
¶
The start time of the task execution.
ImageUrl
¶
Source code in python/potato_head/_potato_head.pyi
format
property
¶
The format of the image URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the image URL.
url
property
¶
The URL of the image.
__init__(url, kind='image-url')
¶
Create an ImageUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the image. |
required |
kind
|
Literal['image-url']
|
The kind of the content. |
'image-url'
|
LogProbs
¶
Source code in python/potato_head/_potato_head.pyi
tokens
property
¶
The log probabilities of the tokens in the response. This is primarily used for debugging and analysis purposes.
Message
¶
Source code in python/potato_head/_potato_head.pyi
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 |
|
content
property
¶
The content of the message
__init__(content)
¶
Create a Message object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
str | ImageUrl | AudioUrl | BinaryContent | DocumentUrl
|
The content of the message. |
required |
Source code in python/potato_head/_potato_head.pyi
bind(name, value)
¶
Bind context to a specific variable in the prompt. This is an immutable operation meaning that it will return a new Message object with the context bound.
Example with Prompt that contains two messages
```python
prompt = Prompt(
model="openai:gpt-4o",
message=[
"My prompt variable is ${variable}",
"This is another message",
],
system_instruction="system_prompt",
)
bounded_prompt = prompt.message[0].bind("variable", "hello world").unwrap() # we bind "hello world" to "variable"
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the variable to bind. |
required |
value
|
str
|
The value to bind the variable to. |
required |
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The message with the context bound. |
Source code in python/potato_head/_potato_head.pyi
bind_mut(name, value)
¶
Bind context to a specific variable in the prompt. This is a mutable operation meaning that it will modify the current Message object.
Example with Prompt that contains two messages
```python
prompt = Prompt(
model="openai:gpt-4o",
message=[
"My prompt variable is ${variable}",
"This is another message",
],
system_instruction="system_prompt",
)
prompt.message[0].bind_mut("variable", "hello world") # we bind "hello world" to "variable"
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the variable to bind. |
required |
value
|
str
|
The value to bind the variable to. |
required |
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The message with the context bound. |
Source code in python/potato_head/_potato_head.pyi
model_dump()
¶
Unwrap the message content and serialize it to a dictionary.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The message dictionary with keys "content" and "role". |
unwrap()
¶
Unwrap the message content.
Returns:
Type | Description |
---|---|
Any
|
A serializable representation of the message content, which can be a string, list, or dict. |
ModelSettings
¶
Source code in python/potato_head/_potato_head.pyi
settings
property
¶
The settings to use for the model.
__init__(settings)
¶
ModelSettings for configuring the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
OpenAIChatSettings | GeminiSettings
|
The settings to use for the model. Currently supports OpenAI and Gemini settings. |
required |
Source code in python/potato_head/_potato_head.pyi
Prompt
¶
Source code in python/potato_head/_potato_head.pyi
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 |
|
message
property
¶
The user message to use in the prompt.
model
property
¶
The model to use for the prompt.
model_identifier
property
¶
Concatenation of provider and model, used for identifying the model in the prompt. This is commonly used with pydantic_ai to identify the model to use for the agent.
model_settings
property
¶
The model settings to use for the prompt.
provider
property
¶
The provider to use for the prompt.
response_json_schema
property
¶
The JSON schema for the response if provided.
system_instruction
property
¶
The system message to use in the prompt.
__init__(message, model, provider, system_instruction=None, model_settings=None, response_format=None)
¶
Prompt for interacting with an LLM API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str | Sequence[str | ImageUrl | AudioUrl | BinaryContent | DocumentUrl] | Message | List[Message]
|
The prompt to use. |
required |
model
|
str
|
The model to use for the prompt |
required |
provider
|
Provider | str
|
The provider to use for the prompt. |
required |
system_instruction
|
Optional[str | List[str]]
|
The system prompt to use in the prompt. |
None
|
model_settings
|
None
|
The model settings to use for the prompt. Defaults to None which means no model settings will be used |
None
|
response_format
|
Optional[BaseModel | Score]
|
The response format to use for the prompt. This is used for Structured Outputs (https://platform.openai.com/docs/guides/structured-outputs?api-mode=chat). Currently, response_format only support Pydantic BaseModel classes and the PotatoHead Score class. The provided response_format will be parsed into a JSON schema. |
None
|
Source code in python/potato_head/_potato_head.pyi
bind(name=None, value=None, **kwargs)
¶
Bind context to a specific variable in the prompt. This is an immutable operation meaning that it will return a new Prompt object with the context bound. This will iterate over all user messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the variable to bind. |
None
|
value
|
str | int | float | bool | list
|
The value to bind the variable to. Must be a JSON serializable type. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to bind to the prompt. This can be used to bind multiple variables at once. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Prompt |
Prompt
|
The prompt with the context bound. |
Source code in python/potato_head/_potato_head.pyi
bind_mut(name=None, value=None, **kwargs)
¶
Bind context to a specific variable in the prompt. This is a mutable operation meaning that it will modify the current Prompt object. This will iterate over all user messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the variable to bind. |
None
|
value
|
str | int | float | bool | list
|
The value to bind the variable to. Must be a JSON serializable type. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to bind to the prompt. This can be used to bind multiple variables at once. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Prompt |
Prompt
|
The prompt with the context bound. |
Source code in python/potato_head/_potato_head.pyi
from_path(path)
staticmethod
¶
Load a prompt from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path to the prompt file. |
required |
Returns:
Name | Type | Description |
---|---|---|
Prompt |
Prompt
|
The loaded prompt. |
model_dump_json()
¶
model_validate_json(json_string)
staticmethod
¶
Validate the model JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_string
|
str
|
The JSON string to validate. |
required |
Returns: Prompt: The prompt object.
save_prompt(path=None)
¶
Save the prompt to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Path]
|
The path to save the prompt to. If None, the prompt will be saved to the current working directory. |
None
|
Source code in python/potato_head/_potato_head.pyi
PromptTokenDetails
¶
Details about the prompt tokens used in a request.
Source code in python/potato_head/_potato_head.pyi
PyTask
¶
Python-specific task interface for Task objects and results
Source code in python/potato_head/_potato_head.pyi
agent_id
property
¶
The ID of the agent that will execute the task.
dependencies
property
¶
The dependencies of the task.
id
property
¶
The ID of the task.
prompt
property
¶
The prompt to use for the task.
result
property
¶
The result of the task if it has been executed, otherwise None.
status
property
¶
The status of the task.
ResponseLogProbs
¶
Source code in python/potato_head/_potato_head.pyi
Score
¶
A class representing a score with a score value and a reason. This is typically used as a response type for tasks/prompts that require scoring or evaluation of results.
Example:
Prompt(
model="openai:gpt-4o",
message="What is the score of this response?",
system_instruction="system_prompt",
response_format=Score,
)
Source code in python/potato_head/_potato_head.pyi
reason
property
¶
The reason for the score.
score
property
¶
The score value.
Task
¶
Source code in python/potato_head/_potato_head.pyi
dependencies
property
¶
The dependencies of the task.
id
property
¶
The ID of the task.
prompt
property
¶
The prompt to use for the task.
status
property
¶
The status of the task.
__init__(agent_id, prompt, dependencies=[], id=None)
¶
Create a Task object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
str
|
The ID of the agent that will execute the task. |
required |
prompt
|
Prompt
|
The prompt to use for the task. |
required |
dependencies
|
List[str]
|
The dependencies of the task. |
[]
|
id
|
Optional[str]
|
The ID of the task. If None, a random uuid7 will be generated. |
None
|
Source code in python/potato_head/_potato_head.pyi
TaskEvent
¶
Source code in python/potato_head/_potato_head.pyi
details
property
¶
Additional details about the event. This can include information such as error messages or other relevant data.
id
property
¶
The ID of the event
status
property
¶
The status of the task at the time of the event.
task_id
property
¶
The ID of the task that the event is associated with.
timestamp
property
¶
The timestamp of the event. This is the time when the event occurred.
updated_at
property
¶
The timestamp of when the event was last updated. This is useful for tracking changes to the event.
workflow_id
property
¶
The ID of the workflow that the task is part of.
TaskList
¶
Usage
¶
Usage statistics for a model response.
Source code in python/potato_head/_potato_head.pyi
completion_tokens
property
¶
The number of completion tokens used in the response.
completion_tokens_details
property
¶
Details about the completion tokens used in the response.
finish_reason
property
¶
The reason why the model stopped generating tokens
prompt_tokens
property
¶
The number of prompt tokens used in the request.
prompt_tokens_details
property
¶
Details about the prompt tokens used in the request.
total_tokens
property
¶
The total number of tokens used in the request and response.
Workflow
¶
Source code in python/potato_head/_potato_head.pyi
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
|
agents
property
¶
The agents in the workflow.
is_workflow
property
¶
Returns True if the workflow is a valid workflow, otherwise False. This is used to determine if the workflow can be executed.
name
property
¶
The name of the workflow.
task_list
property
¶
The tasks in the workflow.
__init__(name)
¶
Create a Workflow object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the workflow. |
required |
__workflow__()
¶
add_agent(agent)
¶
Add an agent to the workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Agent
|
The agent to add to the workflow. |
required |
add_task(task, output_type)
¶
Add a task to the workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Task
|
The task to add to the workflow. |
required |
output_type
|
Optional[Any]
|
The output type to use for the task. This can either be a Pydantic |
required |
Source code in python/potato_head/_potato_head.pyi
add_task_output_types(task_output_types)
¶
Add output types for tasks in the workflow. This is primarily used for when loading a workflow as python objects are not serializable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_output_types
|
Dict[str, Any]
|
A dictionary mapping task IDs to their output types.
This can either be a Pydantic |
required |
Source code in python/potato_head/_potato_head.pyi
add_tasks(tasks)
¶
Add multiple tasks to the workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tasks
|
List[Task]
|
The tasks to add to the workflow. |
required |
execution_plan()
¶
Get the execution plan for the workflow.
Returns:
Type | Description |
---|---|
Dict[str, List[str]]
|
Dict[str, List[str]]: A dictionary where the keys are task IDs and the values are lists of task IDs that the task depends on. |
Source code in python/potato_head/_potato_head.pyi
is_complete()
¶
Check if the workflow is complete.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the workflow is complete, False otherwise. |
model_dump_json()
¶
model_validate_json(json_string, output_types)
staticmethod
¶
Load a workflow from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_string
|
str
|
The JSON string to validate. |
required |
output_types
|
Optional[Dict[str, Any]]
|
A dictionary mapping task IDs to their output types.
This can either be a Pydantic |
required |
Returns:
Name | Type | Description |
---|---|---|
Workflow |
Workflow
|
The workflow object. |
Source code in python/potato_head/_potato_head.pyi
pending_count()
¶
Get the number of pending tasks in the workflow.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of pending tasks in the workflow. |
run(global_context=None)
¶
Run the workflow. This will execute all tasks in the workflow and return when all tasks are complete.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
global_context
|
Optional[Dict[str, Any]]
|
A dictionary of global context to bind to the workflow. All tasks in the workflow will have this context bound to them. |
None
|