fenn.agents

Inheritance diagram of fenn.agents
class fenn.agents.AsyncBatchFlow(start=None)[source]

Bases: AsyncFlow, BatchFlow

class fenn.agents.AsyncBatchNode(max_retries=1, wait=0)[source]

Bases: AsyncNode, BatchNode

class fenn.agents.AsyncFlow(start=None)[source]

Bases: Flow, AsyncNode

async post_async(shared, prep_res, exec_res)[source]
class fenn.agents.AsyncNode(max_retries=1, wait=0)[source]

Bases: Node

async exec_async(prep_res)[source]
async exec_fallback_async(prep_res, exc)[source]
async post_async(shared, prep_res, exec_res)[source]
async prep_async(shared)[source]
async run_async(shared)[source]
class fenn.agents.AsyncParallelBatchFlow(start=None)[source]

Bases: AsyncFlow, BatchFlow

class fenn.agents.AsyncParallelBatchNode(max_retries=1, wait=0)[source]

Bases: AsyncNode, BatchNode

class fenn.agents.BaseNode[source]

Bases: object

__init__()[source]
exec(prep_res)[source]
post(shared, prep_res, exec_res)[source]
prep(shared)[source]
run(shared)[source]
set_params(params)[source]
class fenn.agents.BatchFlow(start=None)[source]

Bases: Flow

class fenn.agents.BatchNode(max_retries=1, wait=0)[source]

Bases: Node

class fenn.agents.Flow(start=None)[source]

Bases: BaseNode

__init__(start=None)[source]
connect(src, dst, action='default')[source]
get_next_node(curr, action)[source]
post(shared, prep_res, exec_res)[source]
start(start)[source]
class fenn.agents.LLMClient(provider=None, model=None, api_key=None, api_key_env=None, base_url=None)[source]

Bases: object

Unified LLM client supporting all major providers via an OpenAI-compatible API.

Parameters:
  • provider (str, optional) – Provider name (e.g. “openai”, “anthropic”, “openrouter”, “ollama”). Auto-detected from model name or base_url when omitted.

  • model (str, optional) – Model identifier. Defaults to the provider’s recommended default.

  • api_key (str, optional) – API key. Takes priority over api_key_env and environment lookup.

  • api_key_env (str, optional) – Environment variable name to read the API key from. Overrides the provider’s default env var (e.g. OPENROUTER_API_KEY).

  • base_url (str, optional) – Custom API base URL. Overrides the provider’s default endpoint.

__init__(provider=None, model=None, api_key=None, api_key_env=None, base_url=None)[source]
ask(prompt, schema=None, retries=3)[source]

Send a single prompt and return the response.

Parameters:
  • prompt (str) – The user message to send.

  • schema (pydantic.BaseModel, optional) – If provided, validates the response against this schema.

  • retries (int) – Retry attempts on rate limit errors.

Return type:

str or pydantic.BaseModel

chat_complete(messages, schema=None, retries=3)[source]

Call the chat completions API with a list of message dicts.

Parameters:
  • messages (list of dict) – Messages in OpenAI format: [{“role”: “user”, “content”: “…”}].

  • schema (pydantic.BaseModel, optional) – If provided, instructs the model to return JSON matching this schema.

  • retries (int) – Number of retry attempts on rate limit errors.

Return type:

str or pydantic.BaseModel

stream(prompt)[source]

Send a prompt and yield response tokens one by one.

Parameters:

prompt (str) – The user message to send.

Yields:

str – Individual tokens from the LLM response.

class fenn.agents.Node(max_retries=1, wait=0)[source]

Bases: BaseNode

__init__(max_retries=1, wait=0)[source]
exec_fallback(prep_res, exc)[source]
class fenn.agents.RAGNode(sources=None, query_key='query', context_key='rag_context', chunks_key='rag_chunks', top_k=5, next_action='default', faiss=False, embedding_provider='local', embedding_model='all-MiniLM-L6-v2', embedding_api_key=None, chunk_mode='smart', persist_path=None)[source]

Bases: Node

Flow node that retrieves relevant context from indexed sources.

Loads and indexes all sources once at construction time, then per run queries the index using shared[query_key] and writes the results into shared[chunks_key] and shared[context_key].

Parameters:
  • sources (str or list of str, optional) – File paths, folder paths, or URLs to load and index on init. Additional sources can be indexed later with add_source().

  • query_key (str) – Key in shared that holds the user query. Default: "query".

  • context_key (str) – Key written into shared with the concatenated chunk text. Default: "rag_context".

  • chunks_key (str) – Key written into shared with the raw list of chunks. Default: "rag_chunks".

  • top_k (int) – Maximum number of chunks to retrieve. Default: 5.

  • next_action (str) – Action string returned by post(), used by Flow.get_next_node(). Default: "default".

  • faiss (bool) – Use FAISS semantic search instead of BM25. Default: False.

  • embedding_provider (str) – Embedding provider (only used when faiss=True). Default: "local".

  • embedding_model (str) – Embedding model (only used when faiss=True). Default: "all-MiniLM-L6-v2".

  • embedding_api_key (str, optional) – API key for the embedding provider.

  • chunk_mode (str) – Document chunking strategy. One of "smart", "paragraphs", "sentences", "fixed". Default: "smart".

  • persist_path (str or Path, optional) – Directory to save/load the FAISS index. Only used when faiss=True.

__init__(sources=None, query_key='query', context_key='rag_context', chunks_key='rag_chunks', top_k=5, next_action='default', faiss=False, embedding_provider='local', embedding_model='all-MiniLM-L6-v2', embedding_api_key=None, chunk_mode='smart', persist_path=None)[source]
add_source(source)[source]

Index an additional source. Returns self for chaining.

exec(query)[source]
post(shared, query, chunks)[source]
prep(shared)[source]