Bots¶
Bot and Agent implementations.
Only the base hierarchy is imported eagerly — AbstractBot, BaseBot,
BasicAgent and Agent — so import parrot.bots stays cheap and never
drags optional satellites (ai-parrot-server, ai-parrot-tools, google-genai…)
into the process. Every concrete bot class is still reachable as
from parrot.bots import X but is resolved lazily on first access.
AbstractBot ¶
AbstractBot(name: str = 'Nav', system_prompt: str = None, llm: Union[str, Type[AbstractClient], AbstractClient, Callable, str] = None, instructions: str = None, tools: List[Union[str, AbstractTool, ToolDefinition]] = None, tool_threshold: float = 0.7, use_kb: bool = False, local_kb: bool = False, debug: bool = False, strict_mode: bool = True, block_on_threat: bool = False, injection_detection: bool = True, injection_probability_threshold: float = 0.98, output_mode: OutputMode = OutputMode.DEFAULT, include_search_tool: bool = False, warmup_on_configure: bool = False, prompt_builder: PromptBuilder = None, prompt_preset: str = None, event_bus: Optional[Any] = None, guardrails: Optional[List[Union[str, Dict[str, Any], Guardrail]]] = None, **kwargs)
Bases: MCPEnabledMixin, DBInterface, LocalKBMixin, EventEmitterMixin, ToolInterface, VectorInterface, ABC
AbstractBot.
This class is an abstract representation a base abstraction for all Chatbots. Inherits from ToolInterface for tool management and VectorInterface for vector store operations.
Initialize the Chatbot with the given configuration.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the bot.
TYPE:
|
system_prompt
|
Custom system prompt for the bot.
TYPE:
|
llm
|
LLM configuration.
TYPE:
|
instructions
|
Additional instructions to append to the system prompt.
TYPE:
|
tools
|
List of tools to initialize.
TYPE:
|
tool_threshold
|
Confidence threshold for tool usage.
TYPE:
|
use_kb
|
Whether to use knowledge bases.
TYPE:
|
debug
|
Enable debug mode.
TYPE:
|
strict_mode
|
Enable strict security mode.
TYPE:
|
block_on_threat
|
Block responses on detected threats.
TYPE:
|
injection_detection
|
Run the prompt-injection detector on user input. Default True. Set False on bots whose inputs are short imperative commands the detector tends to misclassify.
TYPE:
|
injection_probability_threshold
|
Minimum pytector probability (0.0-1.0) required to treat input as an injection. Default 0.98. Raise to reduce false positives.
TYPE:
|
output_mode
|
Default output mode for the bot.
TYPE:
|
include_search_tool
|
Whether to include the 'search_tools' meta-tool. Set to False for agents that rely on RAG context. Default is True.
TYPE:
|
prompt_builder
|
Explicit composable prompt builder. Takes precedence over prompt_preset when provided.
TYPE:
|
prompt_preset
|
Name of a prompt preset to use for composable prompt layers. When set, uses PromptBuilder instead of legacy system_prompt_template. Default is None (legacy behavior).
TYPE:
|
event_bus
|
Optional
TYPE:
|
guardrails
|
Unified guardrails
infrastructure (FEAT-396) — names,
TYPE:
|
**kwargs
|
Additional keyword arguments for configuration.
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 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 | |
prompt_builder
property
writable
¶
Get the composable prompt builder, if set.
is_configured
property
¶
Return whether the bot has completed its configuration.
context_budget
property
¶
The bot's per-turn compaction budget, or None when compaction is disabled.
Resolution (FEAT-525, spec G3/C3):
context_budget=False(constructor kwarg) or thePARROT_COMPACTION_DISABLED=1environment kill switch ⇒None— every render/save goes through FEAT-524's plain path, byte for byte.- An explicit :class:
ContextBudgetinstance ⇒ used as given, except itsmax_turnsis overridden byself.max_context_turnswhen that is set. None/True(the default) ⇒ auto-built from :func:~parrot.memory.compaction.budget.build_default_budgetusingself._llm_model, withmax_turns=self.max_context_turns. When the model is unknown (falls back to the 32k window), this is logged once per bot at INFO — not once per call.
| RETURNS | DESCRIPTION |
|---|---|
Optional[ContextBudget]
|
The resolved budget, or |
memory_key_id
property
¶
Stable per-agent segment of the conversation storage key (FEAT-524).
Every conversation history is keyed by (chatbot, user, session),
and the same value is stamped onto ConversationTurn.chatbot_id so
attribution and storage location always agree.
The value is the explicit chatbot_id when one was supplied (as a
constructor kwarg, or loaded from the database by Chatbot), and
self.name otherwise. It is deliberately not the auto-generated
self.chatbot_id: that default is a fresh uuid4().hex per
process, so keying by it would silently start a new history on every
restart for any bot that never declared an id — scripts, tools, tests
and most ad-hoc BaseBot instances.
Consequence accepted for v1 (spec §7): two different bots created
without a chatbot_id but with the same name share a history.
That is strictly better than today, where they share the completely
un-segmented key.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The key segment, never empty. |
add_event_listener ¶
Add a listener for an event.
.. deprecated::
add_event_listener is deprecated. Use
self.events.subscribe(EventClass, callback) from
parrot.core.events.lifecycle instead.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
set_program ¶
define_store_config ¶
Override this method to declaratively configure the vector store.
Similar to agent_tools(), this is called during configure() lifecycle.
| RETURNS | DESCRIPTION |
|---|---|
Optional[StoreConfig]
|
StoreConfig or None if no store needed. |
Example
def define_store_config(self) -> StoreConfig: return StoreConfig( vector_store='postgres', table='employee_docs', schema='hr', embedding_model={"model": "thenlper/gte-base", "model_type": "huggingface"}, dimension=768, dsn="postgresql+asyncpg://user:pass@host/db", auto_create=True )
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
register_kb ¶
Register a new knowledge base.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_policy_rules ¶
Return policy rules for this bot.
Override in subclasses to provide dynamic rules computed at
instantiation time. The default implementation returns the class
attribute policy_rules.
| RETURNS | DESCRIPTION |
|---|---|
list
|
A list of dicts matching the
TYPE:
|
Example::
class FinanceBot(AbstractBot):
def get_policy_rules(self) -> list:
return [
{"action": "agent:chat", "effect": "allow",
"groups": [self.allowed_group]},
]
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_client ¶
Return the LLM client to use for the next call.
Default: the configured primary client (self._llm). This is the
cooperative-MRO terminal for client-selection mixins (e.g.
ModelSwitchingMixin), which may override it to pick between
multiple configured clients.
| RETURNS | DESCRIPTION |
|---|---|
The
|
class:
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
execute_llm_call
async
¶
Execute a single LLM call through an overridable hook.
Default implementation delegates straight to the client — behavior is
identical to the previous inline await client.ask(**llm_kwargs).
Mixins (e.g. ModelSwitchingMixin) override this to add
cross-provider fallback or contrastive dual-model calls, chaining
super().execute_llm_call(...) for the primary call.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
The already-entered LLM client (inside
TYPE:
|
method
|
Client coroutine to invoke (currently always
TYPE:
|
**llm_kwargs
|
Keyword arguments forwarded to the client method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
The
|
class:
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
configure_conversation_memory ¶
Configure the unified conversation memory system.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
configure_kb
async
¶
Configure Knowledge Base.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
configure
async
¶
Basic Configuration of Bot.
Wrapped in try/except/finally so self._configured is always
flipped to True at the end, even when an inner step raises.
Without this guarantee an uncaught error during configure() leaves
_configured = False; callers that gate on is_configured
(e.g. BotManager.get_bot()) then re-enter configure() on the
next request, which re-registers already-registered toolkits and
raises ToolNameCollisionError on top of the original failure —
masking the real cause.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 | |
post_configure
async
¶
Hook called at the end of :meth:configure.
Runs after the base configuration is complete and self.app has
been set, giving subclasses a safe place to wire up resources that
depend on the aiohttp application (e.g. fetching
app['jira_oauth_manager'] and constructing an OAuth-aware
toolkit, opening a DB pool, registering a scheduler).
The default implementation is a no-op. Subclasses that override
this should await super().post_configure() first to stay
forward-compatible with future base-class setup added here.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
warmup_embeddings
async
¶
Warm up embedding/KB/vector-store models to avoid first-ask latency.
Embedding model loading is delegated to EmbeddingRegistry.preload()
so multiple bots sharing the same model incur only one load. Non-
embedding warmup (vector-store connection pool, KB document loading)
is preserved unchanged.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_conversation_memory ¶
Factory function to create conversation memory instances.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
render_context_history
async
¶
render_context_history(history: Optional[ConversationHistory]) -> Tuple[List[HistoryMessage], Optional[CompactionResult]]
Render a history for this round, budgeted when a context_budget is active.
With no active budget (disabled, or no history/memory), this is
byte-identical to FEAT-524's plain render_history(history,
max_turns=..., current_chatbot_id=...). Otherwise, runs the pure
:func:~parrot.memory.compaction.compact.compact_history pre-pass,
flushes its omissions, and renders the resulting views. A flush
failure degrades to the plain path for this call only — the
boundary is never advanced on a failed flush.
| PARAMETER | DESCRIPTION |
|---|---|
history
|
The history to render.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[HistoryMessage]
|
A tuple of |
Optional[CompactionResult]
|
|
Tuple[List[HistoryMessage], Optional[CompactionResult]]
|
used (budget disabled, no history, no memory, or a flush |
Tuple[List[HistoryMessage], Optional[CompactionResult]]
|
failure) — callers use this to decide whether to build a |
Tuple[List[HistoryMessage], Optional[CompactionResult]]
|
class: |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
estimate_prompt_tokens ¶
estimate_prompt_tokens(rendered: Sequence[HistoryMessage], system_prompt: Optional[str], prompt: str) -> int
Estimate the prompt's token cost for calibration pairing.
| PARAMETER | DESCRIPTION |
|---|---|
rendered
|
The messages about to be sent to the client.
TYPE:
|
system_prompt
|
The effective system prompt for this round.
TYPE:
|
prompt
|
The user's prompt for this round.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The sum of the memory's token counter over every rendered |
int
|
message's content, the system prompt, and the prompt. |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
build_compaction_commit ¶
build_compaction_commit(result: Optional[CompactionResult], prompt_estimate: int) -> Optional[CompactionCommit]
Build the commit save_conversation_turn folds into the persisted state.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
The :class:
TYPE:
|
prompt_estimate
|
This round's estimated prompt token cost (see
:meth:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[CompactionCommit]
|
|
Optional[CompactionCommit]
|
class: |
Optional[CompactionCommit]
|
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
observed_tool_invocations ¶
Return this turn's captured invocations, if it was observed.
The observer is the single source for
ConversationTurn.tool_invocations on an enabled turn: what it
returns replaces the AIMessage.tool_calls conversion instead
of adding to it, so no call is ever listed twice.
| RETURNS | DESCRIPTION |
|---|---|
Optional[List[ToolInvocation]]
|
The captured invocations in dispatch order, or |
Optional[List[ToolInvocation]]
|
the turn was not observed — in which case the caller keeps the |
Optional[List[ToolInvocation]]
|
legacy derivation. |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_conversation_history
async
¶
get_conversation_history(user_id: str, session_id: str, chatbot_id: Optional[str] = None) -> Optional[ConversationHistory]
Get conversation history using unified memory system.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
create_conversation_history
async
¶
create_conversation_history(user_id: str, session_id: str, metadata: Optional[Dict[str, Any]] = None, chatbot_id: Optional[str] = None) -> ConversationHistory
Create new conversation history using unified memory system.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
save_conversation_turn
async
¶
save_conversation_turn(user_id: str, session_id: str, turn: ConversationTurn, *, compaction: Optional[CompactionCommit] = None) -> None
Persist one conversation turn — the single writer (FEAT-524, FEAT-525).
Every bot entry point routes its turn through here. The turn is always
stored under self.memory_key_id; the chatbot_id parameter this
method used to accept was removed on purpose, so no caller can write
into a different agent's history by accident.
| PARAMETER | DESCRIPTION |
|---|---|
user_id
|
Owner of the conversation.
TYPE:
|
session_id
|
Conversation session.
TYPE:
|
turn
|
The turn to persist. Its
TYPE:
|
compaction
|
This round's :class:
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 | |
clear_conversation_history
async
¶
Clear conversation history using unified memory system.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
delete_conversation_history
async
¶
delete_conversation_history(user_id: str, session_id: str, chatbot_id: Optional[str] = None) -> bool
Delete conversation history entirely using unified memory system.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
list_user_conversations
async
¶
List all conversation sessions for a user.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
configure_store_router ¶
configure_store_router(config: Any, ontology_resolver: Optional[Any] = None, multi_store_tool: Optional[MultiSearch] = None) -> None
Configure the store-level router for this bot.
Once configured, :meth:_build_vector_context will route each
query through StoreRouter instead of dispatching directly to
self.store.
Calling this method twice replaces the prior router and cache.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
A :class:
TYPE:
|
ontology_resolver
|
Optional ontology resolver forwarded to
:class:
TYPE:
|
multi_store_tool
|
Optional :class:
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_vector_context
async
¶
get_vector_context(question: str, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: str = 'COSINE', limit: int = 10, score_threshold: float = None, ensemble_config: dict = None, return_sources: bool = False, expand_to_parent: Optional[bool] = None) -> str
Get relevant context from vector store.
Args:
question (str): The user's question to search context for.
search_type (str): Type of search to perform ('similarity', 'mmr', 'ensemble').
search_kwargs (dict): Additional parameters for the search.
expand_to_parent (Optional[bool]): Per-call override for parent expansion
(FEAT-128). None → use bot-level default (self.expand_to_parent).
True → always expand. False → always return children.
metric_type (str): Metric type for vector search (e.g., 'COSINE', 'EUCLIDEAN').
limit (int): Maximum number of context items to retrieve.
score_threshold (float): Minimum score for context relevance.
ensemble_config (dict): Configuration for ensemble search.
return_sources (bool): Whether to extract enhanced source information
Returns:
tuple: (context_string, metadata_dict)
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 | |
is_agent_mode ¶
Check if the bot is configured to operate in agent mode.
is_conversational_mode ¶
Check if the bot is configured for pure conversational mode.
get_operation_mode ¶
Get the current operation mode of the bot.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_tool ¶
list_tool_categories ¶
get_tools_by_category ¶
create_system_prompt
async
¶
create_system_prompt(user_context: str = '', vector_context: str = '', kb_context: str = '', pageindex_context: str = '', metadata: Optional[Dict[str, Any]] = None, memory_context: Optional[str] = None, **kwargs) -> 'Union[str, List]'
Create the complete system prompt for the LLM with user context support.
| PARAMETER | DESCRIPTION |
|---|---|
user_context
|
User-specific context for the database interaction
TYPE:
|
vector_context
|
Vector store context
TYPE:
|
kb_context
|
Knowledge base context (KB Facts)
TYPE:
|
pageindex_context
|
PageIndex tree structure context for tree-based RAG
TYPE:
|
metadata
|
Additional metadata
TYPE:
|
memory_context
|
Optional long-term memory context from LongTermMemoryMixin
TYPE:
|
**kwargs
|
Additional template variables
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 | |
get_user_context
async
¶
Retrieve user-specific context for the database interaction.
| PARAMETER | DESCRIPTION |
|---|---|
user_id
|
User identifier
TYPE:
|
session_id
|
Session identifier
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
User-specific context
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
conversation
abstractmethod
async
¶
conversation(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: str = 'COSINE', use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, return_context: bool = False, memory: Optional[Callable] = None, ensemble_config: dict = None, mode: str = 'adaptive', ctx: Optional[RequestContext] = None, output_mode: OutputMode = OutputMode.DEFAULT, format_kwargs: dict = None, use_tools: Optional[bool] = None, trace_context: Optional[TraceContext] = None, **kwargs) -> AIMessage
Conversation method with vector store and history integration.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
search_type
|
Type of search to perform ('similarity', 'mmr', 'ensemble')
TYPE:
|
search_kwargs
|
Additional search parameters
TYPE:
|
metric_type
|
Metric type for vector search (e.g., 'COSINE', 'EUCLIDEAN')
TYPE:
|
limit
|
Maximum number of context items to retrieve
|
score_threshold
|
Minimum score for context relevance
|
use_vector_context
|
Whether to retrieve context from vector store
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
use_tools
|
Explicit tool switch;
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
The response from the LLM
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
as_markdown ¶
as_markdown(response: AIMessage, return_sources: bool = False, return_context: bool = False, return_tools: bool = False) -> str
Enhanced markdown formatting with context information.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 | |
get_response
async
¶
get_response(response: AIMessage, return_sources: bool = True, return_context: bool = False, return_tools: bool = False) -> AIMessage
Response processing with error handling.
.. versionchanged:: FEAT-396 (TASK-2029)
Now async — runs the OUTPUT GuardrailPipeline (e.g.
SecretsGuardrail redaction) on the finalized response before
returning. Both call sites (bots/base.py) already awaited
from an async context; this is not a new async boundary for
callers, only for this method's own signature.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
session
async
¶
session(ctx: Optional[RequestContext] = None, *, request: 'web.Request' = None, app: Optional[Any] = None, llm: Optional[Any] = None, user_id: Union[str, int, None] = None, session_id: Optional[str] = None, **ctx_kwargs) -> AsyncIterator['AbstractBot']
Bind a RequestContext to the current asyncio task for the block's lifetime.
Replaces the removed retrieval() method. Absorbs PBAC enforcement
and concurrency limiting. Anything awaited beneath this block can call
current_context() and get the same RequestContext object without
explicit parameter threading.
Delegates access control entirely to the PDP evaluator (PBAC). When no PDP is configured (e.g. during development or when policies/ dir is absent), this method is fail-open and allows all requests.
Superuser bypass is handled by policies/defaults.yaml:allow_superuser_all
at priority=100 — no hardcoded superuser check here.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
Pre-built RequestContext. If provided, all other keyword args are ignored (ctx takes precedence).
TYPE:
|
request
|
The aiohttp Request object. Required for session extraction.
TYPE:
|
app
|
Optional aiohttp Application. Falls back to
TYPE:
|
llm
|
Optional LLM override for this request.
TYPE:
|
user_id
|
User identifier stored on the RequestContext.
TYPE:
|
session_id
|
Session identifier stored on the RequestContext.
TYPE:
|
**ctx_kwargs
|
Additional context passed to RequestContext.
DEFAULT:
|
| YIELDS | DESCRIPTION |
|---|---|
AbstractBot
|
The bot instance itself (
TYPE::
|
| RAISES | DESCRIPTION |
|---|---|
HTTPUnauthorized
|
When the PDP evaluator explicitly denies access
for this agent and action |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 | |
shutdown
async
¶
Shutdown.
Optional shutdown method to clean up resources. This method can be overridden in subclasses to perform any necessary cleanup tasks, such as closing database connections, releasing resources, etc. Args: **kwargs: Additional keyword arguments.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
invoke
abstractmethod
async
¶
invoke(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, use_conversation_history: bool = True, memory: Optional[Callable] = None, ctx: Optional[RequestContext] = None, response_model: Optional[Type[BaseModel]] = None, **kwargs) -> AIMessage
Simplified conversation method with adaptive mode and conversation history.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
memory
|
Optional memory callable override
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
resume
async
¶
Resume a suspended conversation turn using the underlying client.
| PARAMETER | DESCRIPTION |
|---|---|
session_id
|
Session identifier
TYPE:
|
user_input
|
The user input text
TYPE:
|
state
|
The suspended state dictionary
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
The response from the LLM
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_conversation_summary
async
¶
Get a summary of the conversation history.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_tools_count ¶
Get the total number of available tools from LLM client.
has_tools ¶
get_available_tools ¶
register_tools ¶
Register multiple tools via LLM client's tool_manager.
post_login
async
¶
Per-user initialization hook run after authentication.
Called by integration wrappers (Telegram, MS Teams, Slack, HTTP)
once per user — typically right after primary authentication
succeeds, or on the first authenticated message. At the time of
invocation the agent's tool_manager has already been swapped
to the per-user clone (in singleton_agent mode) or the whole
agent is already the per-user instance (in full-clone mode), so
any toolkit wiring, credential resolver binding, or cache
priming done here is safely scoped to this user.
Default implementation is a no-op. Subclasses override to seed state that depends on who the caller is (e.g., bind a Jira client to the user's tokens, register user-specific toolkits).
| PARAMETER | DESCRIPTION |
|---|---|
user_context
|
Channel-agnostic identity snapshot produced by
the integration wrapper. See
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
clone_for_user
async
¶
Return an independent agent instance scoped to a single user.
Used by integration wrappers when singleton_agent is disabled
so each user gets a fully isolated agent (no shared mutable
state, no swap-and-restore dance around the shared ToolManager).
This is heavier than cloning only the ToolManager but removes
the need for a cross-user lock and supports tools that keep
state on self.
The default implementation raises NotImplementedError because
reconstructing an agent faithfully requires knowledge its base
class does not have (LLM config, vector store, memory backend,
system prompt, toolkits). Subclasses that want per-user agent
isolation must implement this method — typically by calling
self.__class__(**self._init_kwargs) if they captured their
construction kwargs, or by delegating to a factory registered
with the BotManager.
| PARAMETER | DESCRIPTION |
|---|---|
user_context
|
Channel-agnostic identity snapshot.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
'AbstractBot'
|
A brand-new agent instance. The caller is responsible for |
'AbstractBot'
|
invoking |
'AbstractBot'
|
the instance is ready. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
Default behavior. Opt into
|
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
ask
abstractmethod
async
¶
ask(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: str = 'COSINE', use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, memory: Optional[Callable] = None, ensemble_config: dict = None, ctx: Optional[RequestContext] = None, structured_output: Optional[Union[Type[BaseModel], StructuredOutputConfig]] = None, output_mode: OutputMode = OutputMode.DEFAULT, format_kwargs: dict = None, use_tools: bool = True, trace_context: Optional[TraceContext] = None, **kwargs) -> AIMessage
Ask method with tools always enabled and output formatting support.
Note
BeforeInvokeEvent, AfterInvokeEvent, and
InvokeFailedEvent are emitted by the concrete implementation in
parrot/bots/base.py. This abstract declaration carries the
trace_context kwarg signature that callers must respect; the
event emission lives in BaseBot.ask().
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
search_type
|
Type of search to perform ('similarity', 'mmr', 'ensemble')
TYPE:
|
search_kwargs
|
Additional search parameters
TYPE:
|
metric_type
|
Metric type for vector search
TYPE:
|
use_vector_context
|
Whether to retrieve context from vector store
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
return_sources
|
Whether to return sources in response
TYPE:
|
memory
|
Optional memory handler
TYPE:
|
ensemble_config
|
Configuration for ensemble search
TYPE:
|
ctx
|
Request context
TYPE:
|
output_mode
|
Output formatting mode ('default', 'terminal', 'html', 'json')
TYPE:
|
structured_output
|
Structured output configuration or model
TYPE:
|
format_kwargs
|
Additional kwargs for formatter (show_metadata, show_sources, etc.)
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
AIMessage or formatted output based on output_mode |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
ask_stream
abstractmethod
async
¶
ask_stream(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: str = 'COSINE', use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, memory: Optional[Callable] = None, ensemble_config: dict = None, ctx: Optional[RequestContext] = None, structured_output: Optional[Union[Type[BaseModel], StructuredOutputConfig]] = None, output_mode: OutputMode = OutputMode.DEFAULT, use_tools: bool = True, trace_context: Optional[TraceContext] = None, **kwargs) -> AsyncIterator[Union[str, AIMessage]]
Stream responses using the same preparation logic as :meth:ask.
Yields successive string chunks of the response. The final yielded
element is an :class:~parrot.models.responses.AIMessage containing
the full response text together with response metadata (token usage,
model information, etc.).
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
get_infographic
async
¶
get_infographic(question: str, template: Optional[str] = None, session_id: Optional[str] = None, user_id: Optional[str] = None, use_vector_context: bool = True, use_conversation_history: bool = False, theme: Optional[str] = None, accept: str = 'text/html', ctx: Optional[RequestContext] = None, **kwargs) -> AIMessage
Generate a structured infographic response.
Uses a template to instruct the LLM to return an InfographicResponse with typed blocks (title, hero_card, chart, summary, etc.).
Content negotiation is controlled by the accept parameter:
- "text/html" (default): renders a self-contained HTML document
with inline CSS and ECharts JS — backward compatible.
- "application/json": returns the raw InfographicResponse JSON.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The topic, query, or data description for the infographic.
TYPE:
|
template
|
Template name from the registry (e.g., 'basic', 'executive', 'dashboard', 'comparison', 'timeline', 'minimal'). Pass None to let the LLM decide the block structure freely.
TYPE:
|
session_id
|
Session identifier for conversation history.
TYPE:
|
user_id
|
User identifier.
TYPE:
|
use_vector_context
|
Whether to retrieve context from vector store.
TYPE:
|
use_conversation_history
|
Whether to use conversation history.
TYPE:
|
theme
|
Color theme hint ('light', 'dark', 'corporate', 'vibrant').
TYPE:
|
accept
|
Content type for the response. Defaults to
TYPE:
|
ctx
|
Request context.
TYPE:
|
**kwargs
|
Additional arguments passed to ask().
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
AIMessage with structured_output containing InfographicResponse. |
AIMessage
|
When |
AIMessage
|
the rendered HTML and |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the template name is not found in the registry. |
Example
response = await bot.get_infographic( "Analyze Q4 2025 sales performance", template="executive", theme="corporate", ) infographic = response.structured_output # InfographicResponse for block in infographic.blocks: print(block.type, block)
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 | |
enhance_infographic
async
¶
enhance_infographic(*, skeleton: str, brief: str, data_context: 'Dict[str, Any]', js_bundles_available: 'List[Any]') -> str
Enhance a deterministic infographic skeleton with LLM-generated JS.
The LLM is instructed to add interactivity using only the bundles in
js_bundles_available. The returned HTML is validated by the
toolkit's validate_enhanced_html helper before being persisted.
| PARAMETER | DESCRIPTION |
|---|---|
skeleton
|
Complete HTML document from the deterministic render pass.
TYPE:
|
brief
|
Short description of the desired interactive enhancement.
TYPE:
|
data_context
|
JSON-serialisable dict of DataFrames (as records).
TYPE:
|
js_bundles_available
|
List of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Enhanced HTML string. The caller is responsible for validation. |
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Any LLM completion error is propagated to the caller. |
Note
This method is intentionally simple — it is the caller's
responsibility to validate the returned HTML and fall back to the
skeleton on InfographicValidationError(code='ENHANCE_OUTPUT_INVALID').
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 | |
enhance_interactive
async
¶
enhance_interactive(*, skeleton: str, brief: str, data_context: 'Dict[str, Any]', js_bundles_available: 'List[Any]', library_guide: str = '') -> str
Author a self-contained interactive HTML page from a scaffold skeleton.
The free-form counterpart to :meth:enhance_infographic: the LLM fills
the skeleton's <!-- SLOT:* --> markers and adds interactive JS using
only the whitelisted js_bundles_available. The returned HTML is
validated by the caller (InteractiveToolkit) before persistence.
| PARAMETER | DESCRIPTION |
|---|---|
skeleton
|
Complete HTML skeleton with
TYPE:
|
brief
|
Description of the page to build (slot contents, interactivity).
TYPE:
|
data_context
|
JSON-serialisable source-of-truth data for figures.
TYPE:
|
js_bundles_available
|
TYPE:
|
library_guide
|
Usage snippets + reference types for the chosen libraries (built by the toolkit).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Enhanced HTML string. The caller is responsible for validation and |
str
|
for falling back to the deterministic skeleton on rejection. |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 | |
get_interactive
async
¶
get_interactive(question: str, template: str = 'report', libraries: Optional[List[str]] = None, theme: Optional[str] = None, mode: str = 'enhance', data_context: Optional['Dict[str, Any]'] = None, title: Optional[str] = None) -> AIMessage
Generate a self-contained interactive HTML page (direct, no persistence).
Convenience wrapper that drives the same catalog + enhance pipeline as
:class:~parrot.tools.interactive_toolkit.InteractiveToolkit but returns
the rendered HTML inline in an :class:AIMessage instead of persisting an
artifact (persistence is the toolkit/handler's responsibility).
| PARAMETER | DESCRIPTION |
|---|---|
question
|
Description of the page to build (becomes the enhance brief).
TYPE:
|
template
|
Scaffold template name (
TYPE:
|
libraries
|
Library names to use; defaults to the template's allow-list.
TYPE:
|
theme
|
Theme name (
TYPE:
|
mode
|
TYPE:
|
data_context
|
Optional JSON-serialisable data source for figures.
TYPE:
|
title
|
Optional document title.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
|
AIMessage
|
and whose |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the template name is not in the catalog. |
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 | |
cleanup
async
¶
Clean up agent resources including KB connections.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 | |
BaseBot ¶
BaseBot(name: str = 'Nav', system_prompt: str = None, llm: Union[str, Type[AbstractClient], AbstractClient, Callable, str] = None, instructions: str = None, tools: List[Union[str, AbstractTool, ToolDefinition]] = None, tool_threshold: float = 0.7, use_kb: bool = False, local_kb: bool = False, debug: bool = False, strict_mode: bool = True, block_on_threat: bool = False, injection_detection: bool = True, injection_probability_threshold: float = 0.98, output_mode: OutputMode = OutputMode.DEFAULT, include_search_tool: bool = False, warmup_on_configure: bool = False, prompt_builder: PromptBuilder = None, prompt_preset: str = None, event_bus: Optional[Any] = None, guardrails: Optional[List[Union[str, Dict[str, Any], Guardrail]]] = None, **kwargs)
Bases: AbstractBot
Base Bot implementation providing concrete implementations of abstract methods defined in AbstractBot.
This is the recommended base class for creating custom bots. It provides full implementations of ask, ask_stream, invoke, and conversation methods with support for: - Vector store context retrieval - Knowledge base integration - Conversation history management - Tool usage (agentic mode) - Multiple output formats - Security and prompt injection detection
Subclasses can override these methods to customize behavior or use them as-is for standard bot functionality.
Source code in packages/ai-parrot/src/parrot/bots/abstract.py
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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 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 | |
conversation
async
¶
conversation(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: Optional[str] = None, use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, return_context: bool = False, memory: Optional[Callable] = None, ensemble_config: dict = None, mode: str = 'adaptive', ctx: Optional[RequestContext] = None, output_mode: OutputMode = OutputMode.DEFAULT, format_kwargs: dict = None, system_prompt: Optional[str] = None, use_tools: Optional[bool] = None, trace_context=None, **kwargs) -> AIMessage
Conversation method with vector store and history integration.
.. deprecated::
conversation() is deprecated and will be removed in a future
release. Use :meth:ask instead — it provides the same retrieval
pipeline plus tool support, prompt-injection sanitization, and
long-term memory hooks.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
search_type
|
Type of search to perform ('similarity', 'mmr', 'ensemble')
TYPE:
|
search_kwargs
|
Additional search parameters
TYPE:
|
metric_type
|
Metric type for vector search (e.g., 'EUCLIDEAN_DISTANCE', 'EUCLIDEAN')
TYPE:
|
limit
|
Maximum number of context items to retrieve
|
score_threshold
|
Minimum score for context relevance
|
use_vector_context
|
Whether to retrieve context from vector store
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
use_tools
|
Explicit tool switch for this call.
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
The response from the LLM
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/base.py
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 | |
chat
async
¶
invoke
async
¶
invoke(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, use_conversation_history: bool = True, memory: Optional[Callable] = None, ctx: Optional[RequestContext] = None, response_model: Optional[Type[BaseModel]] = None, **kwargs) -> AIMessage
Simplified conversation method with adaptive mode and conversation history.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
memory
|
Optional memory callable override
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
The response from the LLM
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/base.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 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 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 | |
ask
async
¶
ask(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: Optional[str] = None, use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, memory: Optional[Callable] = None, ensemble_config: dict = None, ctx: Optional[RequestContext] = None, permission_context: Optional[Any] = None, a2ui_surface_state: Optional[Any] = None, structured_output: Optional[Union[Type[BaseModel], StructuredOutputConfig]] = None, system_prompt: Optional[str] = None, output_mode: OutputMode = OutputMode.DEFAULT, format_kwargs: dict = None, use_tools: bool = True, trace_context=None, **kwargs) -> AIMessage
Ask method with tools always enabled and output formatting support.
| PARAMETER | DESCRIPTION |
|---|---|
question
|
The user's question
TYPE:
|
session_id
|
Session identifier for conversation history
TYPE:
|
user_id
|
User identifier
TYPE:
|
search_type
|
Type of search to perform ('similarity', 'mmr', 'ensemble')
TYPE:
|
search_kwargs
|
Additional search parameters
TYPE:
|
system_prompt
|
System prompt to append to the generated system prompt
TYPE:
|
metric_type
|
Metric type for vector search
TYPE:
|
use_vector_context
|
Whether to retrieve context from vector store
TYPE:
|
use_conversation_history
|
Whether to use conversation history
TYPE:
|
return_sources
|
Whether to return sources in response
TYPE:
|
memory
|
Optional memory handler
TYPE:
|
ensemble_config
|
Configuration for ensemble search
TYPE:
|
ctx
|
Request context
TYPE:
|
output_mode
|
Output formatting mode ('default', 'terminal', 'html', 'json')
TYPE:
|
structured_output
|
Structured output configuration or model
TYPE:
|
format_kwargs
|
Additional kwargs for formatter (show_metadata, show_sources, etc.)
TYPE:
|
a2ui_surface_state
|
Optional
TYPE:
|
**kwargs
|
Additional arguments for LLM
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AIMessage
|
AIMessage or formatted output based on output_mode |
Source code in packages/ai-parrot/src/parrot/bots/base.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 | |
ask_stream
async
¶
ask_stream(question: str, session_id: Optional[str] = None, user_id: Optional[str] = None, search_type: str = 'similarity', search_kwargs: dict = None, metric_type: Optional[str] = None, use_vector_context: bool = True, use_conversation_history: bool = True, return_sources: bool = True, memory: Optional[Callable] = None, ensemble_config: dict = None, ctx: Optional[RequestContext] = None, permission_context: Optional[Any] = None, structured_output: Optional[Union[Type[BaseModel], StructuredOutputConfig]] = None, output_mode: OutputMode = OutputMode.DEFAULT, system_prompt: Optional[str] = None, use_tools: bool = True, trace_context=None, **kwargs) -> AsyncIterator[Union[str, AIMessage]]
Stream responses using the same preparation logic as :meth:ask.
use_tools follows the :meth:ask contract: False sends no
function declarations and drops the tool-dependent prompt layers.
Source code in packages/ai-parrot/src/parrot/bots/base.py
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 | |
Agent ¶
Agent(name: str = 'Agent', agent_id: str = 'agent', use_llm: str = 'google', llm: str = None, tools: List[AbstractTool] = None, system_prompt: str = None, human_prompt: str = None, use_tools: bool = True, instructions: Optional[str] = None, dataframes: Optional[Dict[str, DataFrame]] = None, **kwargs)
Bases: BasicAgent
A general-purpose agent with no additional tools.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
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 | |
BasicAgent ¶
BasicAgent(name: str = 'Agent', agent_id: str = 'agent', use_llm: str = 'google', llm: str = None, tools: List[AbstractTool] = None, system_prompt: str = None, human_prompt: str = None, use_tools: bool = True, instructions: Optional[str] = None, dataframes: Optional[Dict[str, DataFrame]] = None, **kwargs)
Bases: Chatbot, NotificationMixin
Represents an Agent in Navigator.
Agents are chatbots that can access to Tools and execute commands. Each Agent has a name, a role, a goal, a backstory, and an optional language model (llm).
These agents are designed to interact with structured and unstructured data sources.
Features: - Built-in MCP server support (no separate mixin needed) - Can connect to HTTP, OAuth, API-key authenticated, and local MCP servers - Automatic tool registration from MCP servers - Compatible with all existing agent functionality - Notification capabilities through various channels (e.g., email, Slack, Teams)
Source code in packages/ai-parrot/src/parrot/bots/agent.py
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 | |
configure
async
¶
Async setup hook (overrides Chatbot.configure).
FEAT-380 (TASK-1944): wiring REPL/pandas tool namespaces into any
registered WorkingMemoryToolkit needs an async round-trip to each
tool's worker process (snapshot()) and therefore cannot run in
the synchronous __init__ anymore — it runs here instead, after
the base configuration completes.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
handle_files
async
¶
Persist every uploaded file and register the tabular ones as DataFrames.
HARD CUT (FEAT-639): previously returned List[str] of DataFrame names.
| PARAMETER | DESCRIPTION |
|---|---|
attachments
|
Mapping of filename to aiohttp FileField, file-like object, or raw bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
{"dataframes": [str, ...], # slugs registered via add_dataframe "files": [dict, ...], # SessionFileRecord dicts, attachable by file_id "errors": [{"filename": str, "error": str}, ...]} |
Source code in packages/ai-parrot/src/parrot/bots/agent.py
agent_tools ¶
set_response ¶
save_document
async
¶
save_document(content: str, prefix: str = 'report', extension: str = 'txt', directory: Optional[Path] = None, subdir: str = 'documents') -> None
Save the document to a file.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
open_prompt
async
¶
Opens a prompt file and returns its content.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
open_query
async
¶
Opens a query string and formats it with provided keyword arguments.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
generate_report
async
¶
generate_report(prompt_file: str, save: bool = False, directory: Optional[Path] = None, **kwargs) -> Tuple[AIMessage, AgentResponse]
Generate a report based on the provided prompt.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
save_transcript
async
¶
save_transcript(transcript: str, filename: str = None, prefix: str = 'transcript', directory: Optional[str] = None, subdir='transcripts') -> str
Save the transcript to a file.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
pdf_report
async
¶
pdf_report(content: str, filename_prefix: str = 'report', directory: Optional[Path] = None, title: str = None, **kwargs) -> str
Generate a report based on the provided prompt.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
markdown_report
async
¶
markdown_report(content: str, filename: Optional[str] = None, filename_prefix: str = 'report', directory: Optional[Path] = None, subdir: str = 'documents', **kwargs) -> str
Saving Markdown report based on provided file.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
speech_report
async
¶
speech_report(report: str, max_lines: int = 15, num_speakers: int = 2, podcast_instructions: Optional[str] = 'for_podcast.txt', directory: Optional[Path] = None, output_directory: Optional[Path] = None, script_model: Optional[str] = None, tts_model: Optional[str] = None, tts_backend: Optional[SpeechBackend] = None, speech_mode: Optional[SpeechMode] = None, **kwargs) -> Dict[str, Any]
Generate a Transcript Report and a Podcast based on findings.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
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 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
report
async
¶
Generate a report based on the provided prompt.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
generate_presentation
async
¶
generate_presentation(content: str, filename_prefix: str = 'report', template_name: Optional[str] = None, pptx_template: str = 'corporate_template.pptx', output_dir: Optional[Path] = None, title: str = None, **kwargs)
Generate a PowerPoint presentation using the provided tool.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
create_speech
async
¶
create_speech(content: str, language: str = 'en-US', only_script: bool = False, **kwargs) -> Dict[str, Any]
Generate a Transcript Report and a Podcast based on findings.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
add_mcp_server
async
¶
Add an MCP server and register its tools.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
MCPServerConfig with connection details
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Example
config = MCPServerConfig( ... name="weather_api", ... url="https://api.example.com/mcp", ... auth_type="api_key", ... auth_config={"api_key": "xxx"} ... ) tools = await agent.add_mcp_server(config)
Source code in packages/ai-parrot/src/parrot/bots/agent.py
setup_mcp_servers
async
¶
Add several MCP servers at once.
Called by the agent registry with the mcp_servers section of an
agent definition. A server that fails to register is logged and
skipped; the remaining servers are still added.
| PARAMETER | DESCRIPTION |
|---|---|
configurations
|
List of MCPServerConfig objects (
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/agent.py
add_mcp_server_url
async
¶
add_mcp_server_url(name: str, url: str, auth_type: Optional[str] = None, auth_config: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None, allowed_tools: Optional[List[str]] = None, blocked_tools: Optional[List[str]] = None, **kwargs) -> List[str]
Convenience method to add a public URL-based MCP server.
This is a simplified interface for adding HTTP MCP servers without manually creating MCPServerConfig objects.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Unique name for the MCP server
TYPE:
|
url
|
Base URL of the MCP server
TYPE:
|
auth_type
|
Optional authentication type ('api_key', 'bearer', 'oauth', 'basic')
TYPE:
|
auth_config
|
Authentication configuration dict
TYPE:
|
headers
|
Additional HTTP headers
TYPE:
|
allowed_tools
|
Whitelist of tool names to register
TYPE:
|
blocked_tools
|
Blacklist of tool names to skip
TYPE:
|
**kwargs
|
Additional MCPServerConfig parameters
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Examples:
>>> # Public server with no auth
>>> tools = await agent.add_mcp_server_url(
... "public_api",
... "https://api.example.com/mcp"
... )
>>> # API key authenticated server
>>> tools = await agent.add_mcp_server_url(
... "weather",
... "https://weather.example.com/mcp",
... auth_type="api_key",
... auth_config={"api_key": "your-key-here"}
... )
>>> # Server with custom headers and tool filtering
>>> tools = await agent.add_mcp_server_url(
... "finance",
... "https://finance.example.com/mcp",
... headers={"User-Agent": "AI-Parrot/1.0"},
... allowed_tools=["get_stock_price", "get_market_data"]
... )
Source code in packages/ai-parrot/src/parrot/bots/agent.py
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 | |
add_local_mcp_server
async
¶
add_local_mcp_server(name: str, script_path: Union[str, Path], interpreter: str = 'python', **kwargs) -> List[str]
Add a local stdio MCP server.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Unique name for the MCP server
TYPE:
|
script_path
|
Path to the MCP server script
TYPE:
|
interpreter
|
Interpreter to use (default: "python")
TYPE:
|
**kwargs
|
Additional MCPServerConfig parameters
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Example
tools = await agent.add_local_mcp_server( ... "local_tools", ... "/path/to/mcp_server.py" ... )
Source code in packages/ai-parrot/src/parrot/bots/agent.py
add_http_mcp_server
async
¶
add_http_mcp_server(name: str, url: str, auth_type: Optional[str] = None, auth_config: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None, **kwargs) -> List[str]
Add an HTTP MCP server with optional authentication.
This is an alias for add_mcp_server_url for backward compatibility.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Unique name for the MCP server
TYPE:
|
url
|
Base URL of the MCP server
TYPE:
|
auth_type
|
Optional authentication type
TYPE:
|
auth_config
|
Authentication configuration
TYPE:
|
headers
|
Additional HTTP headers
TYPE:
|
**kwargs
|
Additional MCPServerConfig parameters
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Source code in packages/ai-parrot/src/parrot/bots/agent.py
add_api_key_mcp_server
async
¶
add_api_key_mcp_server(name: str, url: str, api_key: str, header_name: str = 'X-API-Key', use_bearer_prefix: bool = False, **kwargs) -> List[str]
Add an API-key authenticated MCP server.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Unique name for the MCP server
TYPE:
|
url
|
Base URL of the MCP server
TYPE:
|
api_key
|
API key for authentication
TYPE:
|
header_name
|
Header name for the API key (default: "X-API-Key")
TYPE:
|
use_bearer_prefix
|
If True, prepend "Bearer " to the API key value (default: False)
TYPE:
|
**kwargs
|
Additional MCPServerConfig parameters
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Example
tools = await agent.add_api_key_mcp_server( ... "weather_api", ... "https://api.weather.com/mcp", ... api_key="your-api-key", ... header_name="Authorization" ... )
For Bearer token format (e.g., Fireflies API)¶
tools = await agent.add_api_key_mcp_server( ... "fireflies", ... "https://api.fireflies.ai/mcp", ... api_key="your-api-key", ... header_name="Authorization", ... use_bearer_prefix=True ... )
Source code in packages/ai-parrot/src/parrot/bots/agent.py
remove_mcp_server
async
¶
Remove an MCP server and unregister its tools.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Name of the MCP server to remove
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/agent.py
list_mcp_servers ¶
List all connected MCP servers.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of MCP server names |
get_mcp_client ¶
Get the MCP client for a specific server.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Name of the MCP server
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
MCPClient instance or None |
Source code in packages/ai-parrot/src/parrot/bots/agent.py
shutdown
async
¶
Shutdown the agent and disconnect all MCP servers.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
as_tool ¶
as_tool(tool_name: str = None, tool_description: str = None, use_conversation_method: bool = True, context_filter: Optional[Callable[[AgentContext], AgentContext]] = None) -> AgentTool
Convert this agent into an AgentTool that can be used by other agents.
This allows agents to be composed and used as tools in orchestration scenarios.
| PARAMETER | DESCRIPTION |
|---|---|
tool_name
|
Custom name for the tool (defaults to agent name)
TYPE:
|
tool_description
|
Description of what this agent does
TYPE:
|
use_conversation_method
|
Whether to use conversation() or invoke()
TYPE:
|
context_filter
|
Optional function to filter context before execution
TYPE:
|
question_description
|
Custom description for the query parameter
|
context_description
|
Custom description for the context parameter
|
| RETURNS | DESCRIPTION |
|---|---|
AgentTool
|
Tool wrapper for this agent
TYPE:
|
Example
hr_agent = BasicAgent(name="HRAgent", ...) hr_tool = hr_agent.as_tool( ... tool_description="Handles HR policy questions" ... ) orchestrator.tool_manager.add_tool(hr_tool)
Source code in packages/ai-parrot/src/parrot/bots/agent.py
register_as_tool ¶
register_as_tool(target_agent: BasicAgent, tool_name: str = None, tool_description: str = None, **kwargs) -> None
Register this agent as a tool in another agent's tool manager.
This is a convenience method that combines as_tool() and registration.
| PARAMETER | DESCRIPTION |
|---|---|
target_agent
|
The agent to register this tool with
TYPE:
|
tool_name
|
Custom name for the tool
TYPE:
|
tool_description
|
Description of what this agent does
TYPE:
|
**kwargs
|
Additional arguments for as_tool()
DEFAULT:
|
Example
hr_agent = BasicAgent(name="HRAgent", ...) employee_agent = BasicAgent(name="EmployeeAgent", ...) orchestrator = OrchestratorAgent(name="Orchestrator")
hr_agent.register_as_tool( ... orchestrator, ... tool_description="Handles HR policies and procedures" ... ) employee_agent.register_as_tool( ... orchestrator, ... tool_description="Manages employee data" ... )
Source code in packages/ai-parrot/src/parrot/bots/agent.py
add_dataframe ¶
Add a dataframe to the agent and configure PythonPandasTool.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
pandas DataFrame to add
|
name
|
Optional name for the dataframe. If None, uses df{index}
TYPE:
|
Source code in packages/ai-parrot/src/parrot/bots/agent.py
remove_dataframe ¶
Remove a dataframe by name.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
followup
async
¶
followup(question: str, turn_id: str, data: Any, session_id: Optional[str] = None, user_id: Optional[str] = None, use_conversation_history: bool = True, memory: Optional[Any] = None, ctx: Optional[Any] = None, structured_output: Optional[Any] = None, output_mode: Any = None, format_kwargs: dict = None, return_structured: bool = True, **kwargs) -> AIMessage
Generate a follow-up question using a previous turn as context.
Source code in packages/ai-parrot/src/parrot/bots/agent.py
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 | |