Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): templates examples ts parity #480

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/beeai_framework/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PromptTemplateInput(BaseModel, Generic[T]):
input_schema: type[T] = Field(..., alias="schema")
template: str
functions: dict[str, Callable[[dict], str]] | None = None
defaults: dict[str, str] | None = {}
defaults: dict[str, Any] = {}


class PromptTemplate(Generic[T]):
Expand Down
37 changes: 30 additions & 7 deletions python/docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,48 @@ _Source: [examples/agents/bee.py](/python/examples/agents/bee.py)_

Customize how the agent formats prompts, including the system prompt that defines its behavior.

<!-- embedme examples/templates/agent_sys_prompt.py -->
<!-- embedme examples/templates/system_prompt.py -->

```py
import sys
import traceback

from beeai_framework.agents.runners.default.prompts import (
SystemPromptTemplate,
SystemPromptTemplateInput,
ToolDefinition,
)
from beeai_framework.errors import FrameworkError
from beeai_framework.tools.weather.openmeteo import OpenMeteoTool
from beeai_framework.utils.strings import to_json

tool = OpenMeteoTool()

# Render the granite system prompt
prompt = SystemPromptTemplate.render(SystemPromptTemplateInput(instructions="You are a helpful AI assistant!"))
def main() -> None:
tool = OpenMeteoTool()

tool_def = ToolDefinition(
name=tool.name,
description=tool.description,
input_schema=to_json(tool.input_schema.model_json_schema()),
)

# Render the granite system prompt
prompt = SystemPromptTemplate.render(
instructions="You are a helpful AI assistant!", tools=[tool_def], tools_length=1
)

print(prompt)
print(prompt)


if __name__ == "__main__":
try:
main()
except FrameworkError as e:
traceback.print_exc()
sys.exit(e.explain())

```

_Source: [examples/templates/agent_sys_prompt.py](/python/examples/templates/agent_sys_prompt.py)_
_Source: [examples/templates/system_prompt.py](/python/examples/templates/system_prompt.py)_

The agent uses several templates that you can override:
1. **System Prompt** - Defines the agent's behavior and capabilities
Expand Down
Loading