1"use strict";(self.webpackChunkagora_protocol_website=self.webpackChunkagora_protocol_website||[]).push([["4702"],{3132:function(e,n,o){o.r(n),o.d(n,{metadata:()=>r,contentTitle:()=>l,default:()=>h,assets:()=>c,toc:()=>a,frontMatter:()=>i});var r=JSON.parse('{"id":"python/sender/core","title":"agora.sender.core","description":"Sender Objects","source":"@site/versioned_docs/version-0.2/python/sender/core.md","sourceDirName":"python/sender","slug":"/python/sender/core","permalink":"/docs/python/sender/core","draft":false,"unlisted":false,"editUrl":"https://github.com/agora-protocol/agora-protocol.github.io/blob/main/website/../docs/python/sender/core.md","tags":[],"version":"0.2","lastUpdatedAt":1739741633000,"frontMatter":{"sidebar_label":"core","title":"agora.sender.core"},"sidebar":"reference","previous":{"title":"langchain","permalink":"/docs/python/common/toolformers/langchain"},"next":{"title":"memory","permalink":"/docs/python/sender/memory"}}'),t=o("4246"),s=o("980");let i={sidebar_label:"core",title:"agora.sender.core"},l=void 0,c={},a=[{value:"Sender Objects",id:"sender-objects",level:2},{value:"__init__",id:"__init__",level:4},{value:"make_default",id:"make_default",level:4},{value:"execute_task",id:"execute_task",level:4},{value:"task",id:"task",level:4}];function d(e){let n={code:"code",em:"em",h2:"h2",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h2,{id:"sender-objects",children:"Sender Objects"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-python",children:"class Sender()\n"})}),"\n",(0,t.jsx)(n.p,{children:"Main Sender class responsible for orchestrating protocols, components, and memory."}),"\n",(0,t.jsx)(n.h4,{id:"__init__",children:"__init__"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-python",children:"def __init__(memory: SenderMemory,\n protocol_picker: ProtocolPicker,\n negotiator: SenderNegotiator,\n programmer: SenderProgrammer,\n executor: Executor,\n querier: Querier,\n transporter: SenderTransporter,\n protocol_threshold: int = 5,\n negotiation_threshold: int = 10,\n implementation_threshold: int = 5)\n"})}),"\n",(0,t.jsx)(n.p,{children:"Initialize the Sender with the necessary components and thresholds."}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Arguments"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"memory"})," ",(0,t.jsx)(n.em,{children:"SenderMemory"})," - Memory component for storing protocols and task conversations."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"protocol_picker"})," ",(0,t.jsx)(n.em,{children:"ProtocolPicker"})," - Component responsible for selecting protocols."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"negotiator"})," ",(0,t.jsx)(n.em,{children:"SenderNegotiator"})," - Handles negotiation of protocols."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"programmer"})," ",(0,t.jsx)(n.em,{children:"SenderProgrammer"})," - Generates protocol implementations."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"executor"})," ",(0,t.jsx)(n.em,{children:"Executor"})," - Executes protocol implementations."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"querier"})," ",(0,t.jsx)(n.em,{children:"Querier"})," - Manages querying external services."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"transporter"})," ",(0,t.jsx)(n.em,{children:"SenderTransporter"})," - Handles the transportation of messages."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"protocol_threshold"})," ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations to check existing protocols and see if one is suitable. Defaults to 5."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"negotiation_threshold"})," ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations to negotiate a new protocol. Defaults to 10."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"implementation_threshold"})," ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations using a protocol to write an implementation. Defaults to 5."]}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"make_default",children:"make_default"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-python",children:"@staticmethod\ndef make_default(toolformer,\n storage: Storage = None,\n protocol_picker: ProtocolPicker = None,\n negotiator: SenderNegotiator = None,\n programmer: SenderProgrammer = None,\n executor: Executor = None,\n querier: Querier = None,\n transporter: SenderTransporter = None,\n storage_path: str = './.agora/storage/sender.json',\n protocol_threshold: int = 5,\n negotiation_threshold: int = 10,\n implementation_threshold: int = 5)\n"})}),"\n",(0,t.jsx)(n.p,{children:"Create a default Sender instance with optional custom components."}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Arguments"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"toolformer"})," - The toolformer instance to use for creating components."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"storage"})," ",(0,t.jsx)(n.em,{children:"Storage, optional"})," - Custom storage backend. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"protocol_picker"})," ",(0,t.jsx)(n.em,{children:"ProtocolPicker, optional"})," - Custom protocol picker. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"negotiator"})," ",(0,t.jsx)(n.em,{children:"SenderNegotiator, optional"})," - Custom negotiator. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"programmer"})," ",(0,t.jsx)(n.em,{children:"SenderProgrammer, optional"})," - Custom programmer. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"executor"})," ",(0,t.jsx)(n.em,{children:"Executor, optional"})," - Custom executor. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"querier"})," ",(0,t.jsx)(n.em,{children:"Querier, optional"})," - Custom querier. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"transporter"})," ",(0,t.jsx)(n.em,{children:"SenderTransporter, optional"})," - Custom transporter. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"storage_path"})," ",(0,t.jsx)(n.em,{children:"str, optional"})," - Path to the storage file. Defaults to './sender_storage.json'."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"protocol_threshold"})," ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations to check existing protocols and see if one is suitable. Defaults to 5."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"storage"}),"0 ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations to negotiate a new protocol. Defaults to 10."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"storage"}),"1 ",(0,t.jsx)(n.em,{children:"int, optional"})," - Minimum number of conversations using a protocol to write an implementation. Defaults to 5."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Returns"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"storage"}),"2 - A configured Sender instance."]}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"execute_task",children:"execute_task"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-python",children:"def execute_task(task_id: str,\n task_schema: TaskSchemaLike,\n task_data: dict,\n target: str,\n force_no_protocol: bool = False,\n force_llm: bool = False) -> Any\n"})}),"\n",(0,t.jsx)(n.p,{children:"Execute a task by selecting and running an appropriate protocol or falling back to querying."}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Arguments"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"task_id"})," ",(0,t.jsx)(n.em,{children:"str"})," - The identifier of the task."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"task_schema"})," ",(0,t.jsx)(n.em,{children:"TaskSchemaLike"})," - The schema of the task to be performed."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"task_data"})," - The data required for the task."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"target"})," ",(0,t.jsx)(n.em,{children:"str"})," - The target for which the task is being executed."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"force_no_protocol"})," ",(0,t.jsx)(n.em,{children:"bool, optional"})," - If True, forces execution without a protocol. Defaults to False."]}
1),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"force_llm"})," ",(0,t.jsx)(n.em,{children:"bool, optional"})," - If True, forces execution using a language model. Defaults to False."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Returns"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"Any"})," - The result of the task execution."]}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"task",children:"task"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-python",children:"def task(task_id: Optional[str] = None,\n description: Optional[str] = None,\n input_schema: Optional[dict] = None,\n output_schema: Optional[dict] = None,\n schema_generator: Optional[TaskSchemaGenerator] = None)\n"})}),"\n",(0,t.jsx)(n.p,{children:"Decorator to define a task with optional schemas and description."}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Arguments"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"task_id"})," ",(0,t.jsx)(n.em,{children:"str, optional"})," - The identifier of the task. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"description"})," ",(0,t.jsx)(n.em,{children:"str, optional"})," - A brief description of the task. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"input_schema"})," ",(0,t.jsx)(n.em,{children:"dict, optional"})," - The input schema for the task. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"output_schema"})," ",(0,t.jsx)(n.em,{children:"dict, optional"})," - The output schema for the task. Defaults to None."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"schema_generator"})," ",(0,t.jsx)(n.em,{children:"TaskSchemaGenerator, optional"})," - A generator to fill in missing schema fields. Defaults to None."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Returns"}),":"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"Callable"})," - The decorated function."]}),"\n"]})]})}function h(e={}){let{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},980:function(e,n,o){o.d(n,{Z:function(){return l},a:function(){return i}});var r=o(7378);let t={},s=r.createContext(t);function i(e){let n=r.useContext(s);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.