Agent
autogen.beta.agent.Agent #
Agent(name: str, prompt: PromptType | Iterable[PromptType] = ..., *, config: ModelConfig | None = ..., hitl_hook: HumanHook | None = ..., tools: Iterable[Callable[..., Any] | Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., response_schema: type[TResult], plugins: Iterable[Plugin] = ..., knowledge: KnowledgeConfig | None = ..., tasks: TaskConfig | Literal[False] = ..., assembly: Iterable[AssemblyPolicy] = ...)
Agent(name: str, prompt: PromptType | Iterable[PromptType] = ..., *, config: ModelConfig | None = ..., hitl_hook: HumanHook | None = ..., tools: Iterable[Callable[..., Any] | Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., response_schema: ResponseProto[TResult], plugins: Iterable[Plugin] = ..., knowledge: KnowledgeConfig | None = ..., tasks: TaskConfig | Literal[False] = ..., assembly: Iterable[AssemblyPolicy] = ...)
Agent(name: str, prompt: PromptType | Iterable[PromptType] = ..., *, config: ModelConfig | None = ..., hitl_hook: HumanHook | None = ..., tools: Iterable[Callable[..., Any] | Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., response_schema: UnionType, plugins: Iterable[Plugin] = ..., knowledge: KnowledgeConfig | None = ..., tasks: TaskConfig | Literal[False] = ..., assembly: Iterable[AssemblyPolicy] = ...)
Agent(name: str, prompt: PromptType | Iterable[PromptType] = ..., *, config: ModelConfig | None = ..., hitl_hook: HumanHook | None = ..., tools: Iterable[Callable[..., Any] | Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., response_schema: None = ..., plugins: Iterable[Plugin] = ..., knowledge: KnowledgeConfig | None = ..., tasks: TaskConfig | Literal[False] = ..., assembly: Iterable[AssemblyPolicy] = ...)
Agent(name, prompt=(), *, config=None, hitl_hook=None, tools=(), middleware=(), observers=(), dependencies=None, variables=None, response_schema=None, plugins=(), knowledge=None, tasks=False, assembly=())
Bases: Generic[TResult]
The agentic unit of autogen.beta.
An Agent runs a model loop, invokes tools, honours middleware, surfaces events through observers, and optionally runs the harness primitives (assembly, compaction, aggregation, knowledge store, subtask spawning).
A bare Agent(name, config=cfg) has zero harness middleware and behaves exactly like a plain LLM loop. Harness features are opt-in:
assembly=— assembly policies (e.g.ConversationPolicy,SlidingWindow,AlertPolicy). When non-empty,AssemblerMiddlewareand_HaltCheckMiddlewareare wired in.knowledge=KnowledgeConfig(store=...)— persistent knowledge store, compaction, aggregation.tasks=TaskConfig(...)— opt in to the auto-injectedrun_subtask/run_subtaskstools, and override the LLM config / prompt / tool-inheritance rules for sub-task Agents. Defaults toFalse(sub-task tools disabled).
Source code in autogen/beta/agent.py
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 | |
hitl_hook #
Source code in autogen/beta/agent.py
prompt #
prompt(func: None = None) -> Callable[[PromptHook], PromptHook]
Source code in autogen/beta/agent.py
add_middleware #
Append middleware as the innermost wrapper in the chain.
The added middleware is called last on turn entry and first on turn exit, executing closer to the LLM call than any middleware already registered.
Source code in autogen/beta/agent.py
insert_middleware #
Insert middleware as the outermost wrapper in the chain.
The inserted middleware is called first on turn entry and last on turn exit, executing before all middleware already registered on the agent.
Source code in autogen/beta/agent.py
add_tool #
add_observer #
add_policy #
Append an assembly policy to this agent's chain.
Policies run in order; a newly added policy runs after existing ones. Construction-time ordering validation (warning on suspicious sequences) only runs over policies passed via assembly= — late additions skip the check, so callers should be confident in the ordering they introduce.
Source code in autogen/beta/agent.py
task #
task(title, *, description='', payload=None, capability=None, ttl_seconds=None, context=None, checkpoint_store=None, resume_from=None)
Create a Task whose lifecycle this Agent owns.
Returns an unentered Task; use as async with agent.task(...). Events flow on context.stream if a ConversationContext is supplied; else the Task creates a private MemoryStream on entry and events fire on it (only observers attached to that private stream see them).
Inside the async with block, ag2.task is stamped into context.dependencies so any tool annotated with TaskInject resolves to this Task.
capability tags the task with a capability name. When the agent is registered with the network, the TaskMirror calls Hub.record_observation on the terminal event so the matching Resume.observed[capability] track record updates.
checkpoint_store plus resume_from opt the task into restart-recoverable work: checkpoint(state) writes via the store, and on the next run resume_from=<prior_task_id> reads that state back into task.resumed_state. Standalone agents that don't supply a store pay no cost — checkpoint calls become silent no-ops.
Source code in autogen/beta/agent.py
tool #
tool(function=None, *, name=None, description=None, schema=None, sync_to_thread=True, middleware=())
Source code in autogen/beta/agent.py
observer #
Source code in autogen/beta/agent.py
ask async #
ask(*msg: str | Input, stream: Stream | None = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., prompt: Iterable[str] = ..., config: ModelConfig | None = ..., tools: Iterable[Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., response_schema: type[T2], hitl_hook: HumanHook | None = ...) -> AgentReply[T2, TResult]
ask(msg: str | Input, *, stream: Stream | None = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., prompt: Iterable[str] = ..., config: ModelConfig | None = ..., tools: Iterable[Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., response_schema: ResponseProto[T2], hitl_hook: HumanHook | None = ...) -> AgentReply[T2, TResult]
ask(msg: str | Input, *, stream: Stream | None = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., prompt: Iterable[str] = ..., config: ModelConfig | None = ..., tools: Iterable[Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., response_schema: None, hitl_hook: HumanHook | None = ...) -> AgentReply[str, TResult]
ask(msg: str | Input, *, stream: Stream | None = ..., dependencies: dict[Any, Any] | None = ..., variables: dict[Any, Any] | None = ..., prompt: Iterable[str] = ..., config: ModelConfig | None = ..., tools: Iterable[Tool] = ..., middleware: Iterable[MiddlewareFactory] = ..., observers: Iterable[Observer] = ..., hitl_hook: HumanHook | None = ...) -> AgentReply[TResult, TResult]
ask(*msg, stream=None, dependencies=None, variables=None, prompt=(), config=None, tools=(), middleware=(), observers=(), response_schema=omit, hitl_hook=None)