Assembly: minions
Filename: grok.py
Author: Terry D. Eppler
Created: 09-05-2026
Last Modified By: Terry D. Eppler
Last Modified On: 09-06-2026
grok.py
Copyright © 2026 Terry D. Eppler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov
xAI Grok Minion implementations.
Minion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Grok workflow agent with client-managed local tool execution.
Purpose
Orchestrates provider-native model turns and dispatches registered Fonky or
other local functions while preserving native responses and hosted tools.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default specialization name.
|
name |
str
|
|
model |
str
|
Provider model identifier.
|
instructions |
str
|
|
tools |
list[Tool]
|
Native tool declarations.
|
functions |
dict[str, ToolFunction]
|
Registered local callables by name.
|
max_turns |
int
|
Maximum model turns per execution.
|
api_key |
str
|
Centralized provider credential.
|
prompt |
str
|
Most recently accepted user prompt.
|
client |
Client
|
Native synchronous client.
|
async_client |
AsyncClient
|
Native asynchronous client.
|
chat_client |
Client | AsyncClient | None
|
Most recent chat creation client.
|
chat |
Chat | Chat | None
|
Most recent tool-result recipient.
|
tool_calls |
Sequence[ToolCall]
|
Most recent local tool requests.
|
result |
Response | None
|
Most recent provider response.
|
Initialize a Grok Minion.
Purpose
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Parameters:
| Name |
Type |
Description |
Default |
model
|
str
|
Nonblank provider model identifier.
|
required
|
instructions
|
str
|
Nonblank system instructions.
|
required
|
tools
|
Sequence[Tool] | None
|
Optional native tool declarations.
|
None
|
functions
|
Sequence[ToolFunction] | None
|
Optional matching local callables.
|
None
|
max_turns
|
int
|
Positive model-turn limit; defaults to 10.
|
10
|
name
|
str | None
|
Optional nonblank display name.
|
None
|
Returns:
| Name | Type |
Description |
None |
None
|
Initializes the provider workflow agent.
|
Raises:
| Type |
Description |
ValueError
|
If required configuration, tool correspondence or limits are invalid.
|
TypeError
|
If tool or callable collections are invalid.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
Validate local schema-to-callable pairing.
Purpose
Enforces exact local function correspondence while retaining native hosted tools.
Returns:
| Name | Type |
Description |
None |
None
|
Validates the registered configuration.
|
Source code in grok.py
| def validate_tools( self ) -> None:
"""Validate local schema-to-callable pairing.
Purpose:
Enforces exact local function correspondence while retaining native hosted tools.
Returns:
None: Validates the registered configuration.
"""
names = [ tool.function.name for tool in self.tools if tool.HasField( 'function' ) ]
if len( names ) != len( set( names ) ):
raise ValueError( 'Argument "tools" must contain unique function names!' )
missing = sorted( set( names ).difference( self.functions ) )
extra = sorted( set( self.functions ).difference( names ) )
if missing or extra:
raise ValueError( f'Grok tools and functions must match exactly; missing={missing}, extra={extra}!' )
|
create_chat(client: Client | AsyncClient) -> SyncChat | AsyncChat
create_chat(client: Client) -> SyncChat
create_chat(client: AsyncClient) -> AsyncChat
Create an isolated provider-native chat.
Purpose
Creates the chat with configured instructions and native tool declarations.
Parameters:
| Name |
Type |
Description |
Default |
client
|
Client | AsyncClient
|
Native client for this chat.
|
required
|
Returns:
| Type |
Description |
Chat | Chat
|
SyncChat | AsyncChat: Native chat.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| def create_chat( self, client: Client | AsyncClient ) -> SyncChat | AsyncChat:
"""Create an isolated provider-native chat.
Purpose:
Creates the chat with configured instructions and native tool declarations.
Args:
client (Client | AsyncClient): Native client for this chat.
Returns:
SyncChat | AsyncChat: Native chat.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'client', client )
self.chat_client = client
return self.chat_client.chat.create( model=self.model, messages=[ system( self.instructions ) ], tools=self.tools or None )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'create_chat( self, client: Client | AsyncClient ) -> SyncChat | AsyncChat'
Logger( ).write( exception )
raise exception
|
run(prompt: str) -> Response
Execute the Grok workflow.
Purpose
Processes native model turns and only client-side tool calls.
Parameters:
| Name |
Type |
Description |
Default |
prompt
|
str
|
|
required
|
Returns:
| Name | Type |
Description |
Response |
Response
|
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| def run( self, prompt: str ) -> Response:
"""Execute the Grok workflow.
Purpose:
Processes native model turns and only client-side tool calls.
Args:
prompt (str): Nonblank user input.
Returns:
Response: Final native response.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'prompt', prompt )
if not isinstance( prompt, str ):
raise TypeError( 'Argument "prompt" must be a string!' )
self.prompt = prompt
self.result = None
chat = self.create_chat( self.client )
chat.append( user( self.prompt ) )
for _ in range( self.max_turns ):
response = chat.sample( )
self.result = response
chat.append( response )
tool_calls = [ call for call in response.tool_calls if get_tool_call_type( call ) == 'client_side_tool' ]
if not tool_calls:
return response
self.execute_tools( chat, tool_calls )
raise RuntimeError( f'Grok workflow exceeded {self.max_turns} model turns!' )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'run( self, prompt: str ) -> Response'
Logger( ).write( exception )
raise exception
|
run_async(prompt: str) -> Response
async
Execute the Grok workflow.
Purpose
Processes native model turns and only client-side tool calls.
Parameters:
| Name |
Type |
Description |
Default |
prompt
|
str
|
|
required
|
Returns:
| Name | Type |
Description |
Response |
Response
|
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| async def run_async( self, prompt: str ) -> Response:
"""Execute the Grok workflow.
Purpose:
Processes native model turns and only client-side tool calls.
Args:
prompt (str): Nonblank user input.
Returns:
Response: Final native response.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'prompt', prompt )
if not isinstance( prompt, str ):
raise TypeError( 'Argument "prompt" must be a string!' )
self.prompt = prompt
self.result = None
chat = self.create_chat( self.async_client )
chat.append( user( self.prompt ) )
for _ in range( self.max_turns ):
response = await chat.sample( )
self.result = response
chat.append( response )
tool_calls = [ call for call in response.tool_calls if get_tool_call_type( call ) == 'client_side_tool' ]
if not tool_calls:
return response
await self.execute_tools_async( chat, tool_calls )
raise RuntimeError( f'Grok workflow exceeded {self.max_turns} model turns!' )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'run_async( self, prompt: str ) -> Response'
Logger( ).write( exception )
raise exception
|
stream(prompt: str) -> AsyncIterator[tuple[Response, Chunk]]
async
Execute the Grok workflow.
Purpose
Processes native model turns and only client-side tool calls.
Parameters:
| Name |
Type |
Description |
Default |
prompt
|
str
|
|
required
|
Yields:
| Type |
Description |
AsyncIterator[tuple[Response, Chunk]]
|
tuple[Response, Chunk]: Native response and chunk.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| async def stream( self, prompt: str ) -> AsyncIterator[ tuple[ Response, Chunk ] ]:
"""Execute the Grok workflow.
Purpose:
Processes native model turns and only client-side tool calls.
Args:
prompt (str): Nonblank user input.
Yields:
tuple[Response, Chunk]: Native response and chunk.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'prompt', prompt )
if not isinstance( prompt, str ):
raise TypeError( 'Argument "prompt" must be a string!' )
self.prompt = prompt
self.result = None
chat = self.create_chat( self.async_client )
chat.append( user( self.prompt ) )
for _ in range( self.max_turns ):
response: Response | None = None
async for response, chunk in chat.stream( ):
self.result = response
yield response, chunk
if response is None:
raise RuntimeError( 'Grok streaming returned no response!' )
chat.append( response )
tool_calls = [ call for call in response.tool_calls if get_tool_call_type( call ) == 'client_side_tool' ]
if not tool_calls:
return
await self.execute_tools_async( chat, tool_calls )
raise RuntimeError( f'Grok workflow exceeded {self.max_turns} model turns!' )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'stream( self, prompt: str ) -> AsyncIterator[ tuple[ Response, Chunk ] ]'
Logger( ).write( exception )
raise exception
|
Execute local Grok tool calls.
Purpose
Dispatches registered local functions and appends correlated results to the active chat.
Parameters:
| Name |
Type |
Description |
Default |
chat
|
Chat
|
Native chat receiving tool results.
|
required
|
tool_calls
|
Sequence[ToolCall]
|
Nonempty local tool requests.
|
required
|
Returns:
| Name | Type |
Description |
None |
None
|
Appends results to the native chat.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| def execute_tools( self, chat: SyncChat, tool_calls: Sequence[ chat_pb2.ToolCall ] ) -> None:
"""Execute local Grok tool calls.
Purpose:
Dispatches registered local functions and appends correlated results to the active chat.
Args:
chat (SyncChat): Native chat receiving tool results.
tool_calls (Sequence[chat_pb2.ToolCall]): Nonempty local tool requests.
Returns:
None: Appends results to the native chat.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'chat', chat )
throw_if( 'tool_calls', tool_calls )
if not isinstance( tool_calls, Sequence ) or isinstance( tool_calls, (str, bytes, bytearray) ):
raise TypeError( 'Argument "tool_calls" must be a sequence!' )
self.chat = chat
self.tool_calls = tool_calls
recipient = self.chat
calls = self.tool_calls
for tool_call in calls:
function = self.functions.get( tool_call.function.name )
if function is None:
raise ValueError( f'Grok requested an unregistered tool: "{tool_call.function.name}"!' )
arguments = self.parse_arguments( tool_call.function.arguments )
if iscoroutinefunction( function ):
raise TypeError( f'Tool "{tool_call.function.name}" requires async execution!' )
output = function( **arguments )
if isawaitable( output ):
if asyncio.iscoroutine( output ):
output.close( )
raise TypeError( f'Tool "{tool_call.function.name}" requires async execution!' )
recipient.append( tool_result( self.serialize_result( output ), tool_call_id=tool_call.id ) )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'execute_tools( self, chat: SyncChat, tool_calls: Sequence[ chat_pb2.ToolCall ] ) -> None'
Logger( ).write( exception )
raise exception
|
Execute local Grok tool calls.
Purpose
Dispatches registered local functions and appends correlated results to the active chat.
Parameters:
| Name |
Type |
Description |
Default |
chat
|
Chat
|
Native chat receiving tool results.
|
required
|
tool_calls
|
Sequence[ToolCall]
|
Nonempty local tool requests.
|
required
|
Returns:
| Name | Type |
Description |
None |
None
|
Appends results to the native chat.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| async def execute_tools_async( self, chat: AsyncChat, tool_calls: Sequence[ chat_pb2.ToolCall ] ) -> None:
"""Execute local Grok tool calls.
Purpose:
Dispatches registered local functions and appends correlated results to the active chat.
Args:
chat (AsyncChat): Native chat receiving tool results.
tool_calls (Sequence[chat_pb2.ToolCall]): Nonempty local tool requests.
Returns:
None: Appends results to the native chat.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'chat', chat )
throw_if( 'tool_calls', tool_calls )
if not isinstance( tool_calls, Sequence ) or isinstance( tool_calls, (str, bytes, bytearray) ):
raise TypeError( 'Argument "tool_calls" must be a sequence!' )
self.chat = chat
self.tool_calls = tool_calls
recipient = self.chat
calls = self.tool_calls
for tool_call in calls:
function = self.functions.get( tool_call.function.name )
if function is None:
raise ValueError( f'Grok requested an unregistered tool: "{tool_call.function.name}"!' )
arguments = self.parse_arguments( tool_call.function.arguments )
if iscoroutinefunction( function ):
output = await function( **arguments )
else:
output = await asyncio.to_thread( function, **arguments )
if isawaitable( output ):
output = await output
recipient.append( tool_result( self.serialize_result( output ), tool_call_id=tool_call.id ) )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'execute_tools_async( self, chat: AsyncChat, tool_calls: Sequence[ chat_pb2.ToolCall ] ) -> None'
Logger( ).write( exception )
raise exception
|
parse_arguments(arguments: str) -> dict[str, object]
staticmethod
Parse model-supplied arguments.
Purpose
Decodes external JSON without rejecting a valid empty keyword object.
Parameters:
| Name |
Type |
Description |
Default |
arguments
|
str
|
JSON object text supplied by the provider.
|
required
|
Returns:
| Type |
Description |
dict[str, object]
|
dict[str, object]: Decoded keyword arguments.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| @staticmethod
def parse_arguments( arguments: str ) -> dict[ str, object ]:
"""Parse model-supplied arguments.
Purpose:
Decodes external JSON without rejecting a valid empty keyword object.
Args:
arguments (str): JSON object text supplied by the provider.
Returns:
dict[str, object]: Decoded keyword arguments.
Raises:
Error: If validation or execution fails.
"""
try:
throw_if( 'arguments', arguments )
if not isinstance( arguments, str ):
raise TypeError( 'Tool arguments must be JSON text!' )
values = json.loads( arguments )
if not isinstance( values, dict ):
raise TypeError( 'Tool arguments must be a JSON object!' )
return values
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'parse_arguments( arguments: str ) -> dict[ str, object ]'
Logger( ).write( exception )
raise exception
|
serialize_result(result: object) -> str
staticmethod
Serialize a local tool result.
Purpose
Preserves text and JSON-compatible structured results at the provider boundary.
Parameters:
| Name |
Type |
Description |
Default |
result
|
object
|
Tool output, including null and empty values.
|
required
|
Returns:
| Name | Type |
Description |
str |
str
|
Provider-compatible result content.
|
Raises:
| Type |
Description |
Error
|
If validation or execution fails.
|
Source code in grok.py
| @staticmethod
def serialize_result( result: object ) -> str:
"""Serialize a local tool result.
Purpose:
Preserves text and JSON-compatible structured results at the provider boundary.
Args:
result (object): Tool output, including null and empty values.
Returns:
str: Provider-compatible result content.
Raises:
Error: If validation or execution fails.
"""
try:
if isinstance( result, str ):
return result
return json.dumps( serialize_value( result ), ensure_ascii=False, allow_nan=False )
except Error:
raise
except Exception as e:
if 'fonky.boogr' in sys.modules and isinstance( e, sys.modules[ 'fonky.boogr' ].Error ):
raise
exception = Error( e )
exception.module = 'grok'
exception.cause = 'Minion'
exception.method = 'serialize_result( result: object ) -> str'
Logger( ).write( exception )
raise exception
|
DataMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for data workflows.
Purpose
Provides the Data Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
GovernanceMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for governance workflows.
Purpose
Provides the Governance Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
ResearchMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for research workflows.
Purpose
Provides the Research Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
CodingMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for software workflows.
Purpose
Provides the Coding Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
WritingMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for writing workflows.
Purpose
Provides the Writing Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
PlanningMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for planning workflows.
Purpose
Provides the Planning Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
ComplianceMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for compliance, legal, and budget workflows.
Purpose
Provides the Compliance Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
BusinessMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for business, finance, and marketing workflows.
Purpose
Provides the Business Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
ImageGenerationMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for image-generation workflows.
Purpose
Provides the Image Generation Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
ImageAnalysisMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for image-analysis workflows.
Purpose
Provides the Image Analysis Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
ImageEditingMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for image-editing workflows.
Purpose
Provides the Image Editing Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
TranslationMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for translation workflows.
Purpose
Provides the Translation Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
TranscriptionMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for transcription workflows.
Purpose
Provides the Transcription Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|
SpeechMinion(model: str, instructions: str, tools: Sequence[chat_pb2.Tool] | None = None, functions: Sequence[ToolFunction] | None = None, max_turns: int = 10, name: str | None = None)
Bases: Minion
Grok Minion specialized for speech workflows.
Purpose
Provides the Speech Minion specialization of the native Grok workflow agent.
Inherits execution, configuration and tool orchestration from Minion.
Attributes:
| Name |
Type |
Description |
minion_name |
str
|
Default display name for this specialization.
|
Source code in grok.py
| def __init__( self, model: str, instructions: str, tools: Sequence[ chat_pb2.Tool ] | None=None, functions: Sequence[ ToolFunction ] | None=None, max_turns: int=10, name: str | None=None ) -> None:
"""Initialize a Grok Minion.
Purpose:
Stores configuration, registers native schemas and matching local functions,
and initializes the provider clients.
Args:
model (str): Nonblank provider model identifier.
instructions (str): Nonblank system instructions.
tools (Sequence[chat_pb2.Tool] | None): Optional native tool declarations.
functions (Sequence[ToolFunction] | None): Optional matching local callables.
max_turns (int): Positive model-turn limit; defaults to 10.
name (str | None): Optional nonblank display name.
Returns:
None: Initializes the provider workflow agent.
Raises:
ValueError: If required configuration, tool correspondence or limits are invalid.
TypeError: If tool or callable collections are invalid.
"""
if not isinstance( model, str ) or not model.strip( ):
raise ValueError( 'Argument "model" must be a nonblank string!' )
if not isinstance( instructions, str ) or not instructions.strip( ):
raise ValueError( 'Argument "instructions" must be a nonblank string!' )
if type( max_turns ) is not int or max_turns < 1:
raise ValueError( 'Argument "max_turns" must be a positive integer!' )
self.name = self.minion_name if name is None else name
if not isinstance( self.name, str ) or not self.name.strip( ):
raise ValueError( 'Argument "name" must be a nonblank string!' )
if tools is not None and (not isinstance( tools, Sequence ) or isinstance( tools, (str, bytes, bytearray) )):
raise TypeError( 'Argument "tools" must be a sequence of native tools!' )
if functions is not None and (not isinstance( functions, Sequence ) or isinstance( functions, (str, bytes, bytearray) )):
raise TypeError( 'Argument "functions" must be a sequence of callables!' )
self.model = model
self.instructions = instructions
self.tools = list( tools ) if tools is not None else [ ]
function_list = list( functions ) if functions is not None else [ ]
if not all( callable( function ) for function in function_list ):
raise TypeError( 'Argument "functions" must contain callables!' )
self.functions = { function.__name__: function for function in function_list }
if len( self.functions ) != len( function_list ):
raise ValueError( 'Argument "functions" must contain unique names!' )
self.max_turns = max_turns
self.api_key = cfg.XAI_API_KEY
self.prompt = ''
self.result = None
self.chat_client = None
self.chat = None
self.tool_calls = [ ]
self.validate_tools( )
if not self.api_key.strip( ):
raise ValueError( 'Configuration "XAI_API_KEY" cannot be empty!' )
self.client = Client( api_key=self.api_key )
self.async_client = AsyncClient( api_key=self.api_key )
|