Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/agentics/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .agentics import AG

__all__ = ["AG"]
10 changes: 5 additions & 5 deletions src/agentics/core/agentics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from functools import partial, reduce
from typing import (
Any,
Callable,
Dict,
Generic,
List,
Expand All @@ -35,7 +34,6 @@
from agentics.core.async_executor import (
PydanticTransducerCrewAI,
PydanticTransducerMellea,
PydanticTransducerVLLM,
aMap,
)
from agentics.core.atype import (
Expand Down Expand Up @@ -1143,7 +1141,7 @@ def product(self, other: AG) -> AG:
def merge_states(self, other: AG) -> AG:
"""
Merge states of two AGs pairwise.

The 'other' AG's fields take precedence over 'self' fields when there are conflicts.
This ensures that newly generated data (other) overwrites existing data (self).
"""
Expand Down Expand Up @@ -1276,13 +1274,15 @@ def rebind_atype(
"amap_batch_size": self.amap_batch_size,
"areduce_batches": copy(self.areduce_batches),
"save_amap_batches_to_path": self.save_amap_batches_to_path,
"crew_prompt_params": copy(self.crew_prompt_params) if self.crew_prompt_params else None,
"crew_prompt_params": (
copy(self.crew_prompt_params) if self.crew_prompt_params else None
),
"vector_store": self.vector_store,
}
# Only include atype_code if it's not None (to avoid validation error)
if self.atype_code is not None:
init_params["atype_code"] = self.atype_code

new_ag = AG(**init_params)

for state in self.states:
Expand Down
5 changes: 2 additions & 3 deletions src/agentics/core/default_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dataclasses import asdict, is_dataclass
from typing import Any, Callable, Generic, List, Optional, Type, TypeVar, Union
from typing import Callable, List, Optional, Type, TypeVar, Union

from pydantic import BaseModel, Field, create_model
from pydantic import BaseModel, Field


class Astr(BaseModel):
Expand Down
8 changes: 3 additions & 5 deletions src/agentics/core/mellea_pydantic_transducer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Put this at the top of your script
import asyncio
import logging
import os
import warnings
from typing import Optional, Type
from typing import Type

os.environ["TQDM_DISABLE"] = "1"

Expand All @@ -21,9 +20,8 @@ def no_bar(iterable=None, *args, **kwargs):
# Override only the *function*, not the module, not the class
tqdm.tqdm = no_bar

import mellea
from mellea.stdlib.sampling import RejectionSamplingStrategy
from pydantic import BaseModel
import mellea # noqa: E402
from pydantic import BaseModel # noqa: E402

# Silence asyncio’s “Unclosed client session” ERROR logs
logging.getLogger("asyncio").setLevel(logging.CRITICAL)
Expand Down
3 changes: 1 addition & 2 deletions src/agentics/core/semantic_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
# sem_agg Aggregate across all records (e.g. for summarization)
# sem_topk Order the records by some natural language sorting criteria
# sem_join Join two datasets based on a natural language predicate
import pathlib
from typing import Type

import pandas as pd
from pydantic import BaseModel, Field
from pydantic import BaseModel

from agentics import AG
from agentics.core.atype import create_pydantic_model
Expand Down
53 changes: 22 additions & 31 deletions src/agentics/core/transducible_functions.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import functools
import inspect
import logging
import types
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, Protocol, Type, get_args

from dotenv import load_dotenv
from pydantic import BaseModel
from pydantic import BaseModel, create_model
from pydantic._internal._model_construction import ModelMetaclass # Pydantic v2

from agentics.core.agentics import AG
from agentics.core.atype import AGString
from agentics.core.default_types import GeneratedAtype
from agentics.core.utils import (
get_function_io_types,
import_last_function_from_code,
import_pydantic_from_code,
percent_non_empty_fields,
)

load_dotenv()
import functools
import inspect
import logging
from typing import Any, Callable, Tuple, get_args

from agentics.core.default_types import GeneratedAtype
from agentics.core.utils import get_function_io_types, percent_non_empty_fields

logging.getLogger("huggingface_hub.utils._http").setLevel(logging.ERROR)

Expand Down Expand Up @@ -377,10 +378,6 @@ def With(model, **kwargs):
return TransductionConfig(model, **kwargs)


from pydantic import BaseModel
from pydantic._internal._model_construction import ModelMetaclass # Pydantic v2


def _function_lshift(f, InputType):
"""
f << X = composition
Expand Down Expand Up @@ -537,44 +534,38 @@ async def semantic_merge(instance1: BaseModel, instance2: BaseModel) -> BaseMode
return merged_instance[0]


from typing import Type

from pydantic import BaseModel, create_model

from agentics import AG
from agentics.core.atype import AGString

async def generate_prototypical_instances(
type: Type[BaseModel],
n_instances: int = 10,
llm: Any = AG.get_llm_provider(),
instructions: str = None,
) -> list[BaseModel]:

DynamicModel = create_model(
"ListOfObjectsOfGivenType",
instances=(list[type] | None, None), # REQUIRED field
)
"ListOfObjectsOfGivenType",
instances=(list[type] | None, None), # REQUIRED field
)
if llm:

full_instructions = f"""
Generate list of {n_instances} random instances of the following type
{type.model_json_schema()}.
fill all attributed for each generated instance
"""
if instructions:
full_instructions += "Adhere to the following instructions \n" + instructions

full_instructions += (
"Adhere to the following instructions \n" + instructions
)

target = AG(
atype=DynamicModel,
instructions=full_instructions,
llm=llm,
)
generated = await (target << AGString(string =" "))
generated = await (target << AGString(string=" "))
return generated.states[0].instances
else: return [DynamicModel()]

from typing import Any, Awaitable, Protocol
else:
return [DynamicModel()]


class TransducibleFn(Protocol):
Expand Down
30 changes: 7 additions & 23 deletions src/agentics/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import ast
import asyncio
import datetime
import hashlib
import inspect
import json
import math
import os
import re
import textwrap
import types
from collections.abc import Iterable
from typing import (
Annotated,
Expand All @@ -27,8 +33,8 @@
import httpx
import pandas as pd
from dotenv import load_dotenv
from jsonfinder import jsonfinder
from loguru import logger
from numerize.numerize import numerize
from openai import APIStatusError, AsyncOpenAI
from pydantic import BaseModel, Field, create_model
from pydantic.fields import FieldInfo
Expand Down Expand Up @@ -166,9 +172,6 @@ def sanitize_field_name(name: str) -> str:
return re.sub(r"[^\w]", "", name)


import math


def sanitize_dict_keys(obj):
"""
Recursively sanitize dictionary keys and values.
Expand Down Expand Up @@ -433,11 +436,6 @@ class ATypeList(BaseModel):
)


import json

from jsonfinder import jsonfinder


def extract_json_objects(text: str, expected_type: Type) -> List[BaseModel]:
"""
Scan `text` and return a list of (start_index, end_index, parsed_obj)
Expand Down Expand Up @@ -490,12 +488,6 @@ def llm_friendly_json(model: type[BaseModel]) -> str:
return json.dumps(simple, indent=4)


import ast
import textwrap
import types
from typing import Callable


def import_last_function_from_code(code: str) -> Callable:
"""
Execute the code and return ONLY the last user-defined function,
Expand Down Expand Up @@ -583,9 +575,6 @@ def import_last_function_from_code(code: str) -> Callable:
return fn


import hashlib


def compute_function_hash(
fn: Callable | str,
# SourceModel:Type[BaseModel] | str = None,
Expand Down Expand Up @@ -676,11 +665,6 @@ def get_function_io_types(
return input_types, output_type


from typing import Optional, Type

from pydantic import BaseModel, create_model


def make_transduction_type(
source: Type[BaseModel],
target: Type[BaseModel],
Expand Down
7 changes: 1 addition & 6 deletions src/agentics/core/vector_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import Any, Dict, List

import numpy as np
from pydantic import BaseModel, ConfigDict
Expand All @@ -23,11 +23,6 @@ def embed(self, texts: List[str]) -> np.ndarray:
return vecs.astype(np.float32)


from typing import Any, Dict, List

from pydantic import BaseModel, ConfigDict


class HNSWStore:
def __init__(
self,
Expand Down