kodeagent.fca.FunctionCallingAgent#

class kodeagent.fca.FunctionCallingAgent(model_name: str, tools: list[Callable] | None = None, system_prompt: str = "You are a helpful assistant that uses tools to solve tasks. Always use a tool.\nIf you have gathered enough information to answer the user's request, you MUST call the `final_answer` tool with your result.\nIf you have called the same tool multiple times without success, STOP and provide your best possible answer using the `final_answer` tool.\nDo not get stuck in a loop. If you cannot solve the task, explain why using the `final_answer` tool.\nUnless otherwise specified, answer in the same language as the users' task input.\n", loop_detection_threshold: int = 3, litellm_params: dict | None = None, max_tool_result_chars: int = 3000, one_line_doc: bool = True, tool_timeout: float = 30.0)[source]#

An agent that uses native function calling to solve tasks, optimized for Small Language Models (SLMs). If you’re using Ollama, make sure to select a model that supports function calling, such as ‘ollama/qwen3:8b-q8_0’.

Initialize the FunctionCallingAgent.

Parameters:
  • model_name – Model identifier for LiteLLM.

  • tools – Optional list of callable tools.

  • system_prompt – System prompt for the agent.

  • loop_detection_threshold – Number of consecutive same tool calls before triggering loop detection. Default is 3.

  • litellm_params – Optional dictionary of parameters to pass to LiteLLM calls.

  • max_tool_result_chars – Maximum number of characters to store in chat history for each tool result. Longer results are truncated with a note. Full results are preserved separately for final answer preparation.

  • one_line_doc – If True, use only the first line of the tool’s docstring for the schema. This can help reduce token usage for SLMs. If False, the full docstring is used, which may provide more context but at the cost of more tokens.

  • tool_timeout – Seconds to wait for a single tool call before cancelling it and returning an error result. Default is 30.0.

__init__(model_name: str, tools: list[Callable] | None = None, system_prompt: str = "You are a helpful assistant that uses tools to solve tasks. Always use a tool.\nIf you have gathered enough information to answer the user's request, you MUST call the `final_answer` tool with your result.\nIf you have called the same tool multiple times without success, STOP and provide your best possible answer using the `final_answer` tool.\nDo not get stuck in a loop. If you cannot solve the task, explain why using the `final_answer` tool.\nUnless otherwise specified, answer in the same language as the users' task input.\n", loop_detection_threshold: int = 3, litellm_params: dict | None = None, max_tool_result_chars: int = 3000, one_line_doc: bool = True, tool_timeout: float = 30.0)[source]#

Initialize the FunctionCallingAgent.

Parameters:
  • model_name – Model identifier for LiteLLM.

  • tools – Optional list of callable tools.

  • system_prompt – System prompt for the agent.

  • loop_detection_threshold – Number of consecutive same tool calls before triggering loop detection. Default is 3.

  • litellm_params – Optional dictionary of parameters to pass to LiteLLM calls.

  • max_tool_result_chars – Maximum number of characters to store in chat history for each tool result. Longer results are truncated with a note. Full results are preserved separately for final answer preparation.

  • one_line_doc – If True, use only the first line of the tool’s docstring for the schema. This can help reduce token usage for SLMs. If False, the full docstring is used, which may provide more context but at the cost of more tokens.

  • tool_timeout – Seconds to wait for a single tool call before cancelling it and returning an error result. Default is 30.0.

Methods

__init__(model_name[, tools, system_prompt, ...])

Initialize the FunctionCallingAgent.

response(rtype, value[, channel, metadata])

Prepare a response to be sent by the agent.

run(task[, files, max_iterations, ...])

Main loop for the agent to process input and execute tools until finished.